title: What benefit do I get from JSVC over just using systemd?
body: <p>The Tomcat documentation <a href="http://tomcat.apache.org/tomcat-8.0-doc/setup.html">describes</a> the process of compiling and installing <a href="http://commons.apache.org/proper/commons-daemon/jsvc.html">JSVC</a> which can be used to run Tomcat as a daemon. As per my understanding, JSVC has two benefits:</p>
  
  <ol>
  <li>It launches as root allowing for the use of a privileged port (like 80 or 443).</li>
  <li>It creates a "controller process" which will monitor a "controlled process" (the main Java thread) and restart the process on failure.</li>
  </ol>
  
  <p>I've been learning <a href="http://www.freedesktop.org/wiki/Software/systemd/">systemd</a>, including the <a href="http://www.freedesktop.org/software/systemd/man/systemd.service.html">service unit configuration</a>. Based on my limited understanding, systemd is able to perform the same tasks as JSVC if I set <code>User=tomcat</code> (using the desired username) and <code>Restart=on-failure</code> in my <code>tomcat.service</code> configuration file.</p>
  
  <p>Using <strong>JSVC</strong>, I would expect <code>tomcat.service</code> to look something like this:</p>
  
  <pre><code>[Unit]
  Description=Apache Tomcat
  After=network.target
  
  [Service]
  Environment=CATALINA_PID=/var/run/tomcat.pid
  Environment=JAVA_HOME=/path/to/java
  Environment=CATALINA_HOME=/opt/tomcat
  ...
  
  ExecStart=/opt/tomcat/bin/jsvc \
      -Dcatalina.home=${CATALINA_HOME} \
      -user tomcat \
      -java-home ${JAVA_HOME} \
      -pidfile ${CATALINA_PID} \
      ...
      org.apache.catalina.startup.Bootstrap
  
  ExecStop=/opt/tomcat/bin/jsvc \
      -pidfile ${CATALINA_PID} \
      ...
      -stop \
      org.apache.catalina.startup.Bootstrap
  
  [Install]
  WantedBy=multi-user.target
  </code></pre>
  
  <p>Using <strong>systemd</strong>, I would expect <code>tomcat.service</code> to look something like this:</p>
  
  <pre><code>[Unit]
  Description=Apache Tomcat
  After=network.target
  
  [Service]
  Type=forking  
  PIDFile=/var/run/tomcat.pid
  User=tomcat
  Group=tomcat
  Environment=JAVA_HOME=/path/to/java
  Environment=CATALINA_HOME=/opt/tomcat
  ...
  
  Restart=on-failure
  
  ExecStart=/opt/tomcat/bin/startup.sh
  ExecStop=/opt/tomcat/bin/shutdown.sh
  
  [Install]
  WantedBy=multi-user.target
  </code></pre>
  
  <p>My preference is using just systemd as it's already there and I have to (should) use it anyway. I am however uncertain as to whether or not I will be missing any benefit of using JSVC that I am overlooking.</p>
  
  <p><strong>What can be achieved by JSVC that cannot be achieved by systemd if I want to run Tomcat as a daemon?</strong></p>
  
  <p><strong>Also, if systemd is able to perform the same tasks as JSVC as well as JSVC, I'd also like to ask for any configuration tips you may offer to best achieve the benefits of JSVC using just systemd.</strong></p>