Uploaded image for project: 'Jenkins'
  1. Jenkins
  2. JENKINS-41218

Provide native systemd unit

    XMLWordPrintable

    Details

    • Type: Improvement
    • Status: Open (View Workflow)
    • Priority: Minor
    • Resolution: Unresolved
    • Component/s: packaging
    • Labels:
      None
    • Similar Issues:

      Description

      Currently debian packages (and presumably redhat/suse/etc) ship with old style SysV init.d file.

      Most distributions are now systemd based, and to be able to make use of it's additional features it would be useful have /lib/systemd/system/jenkins.service file.

      This would allow features like systemd's restart functionality to work (useful when Jenkins occasionally crashes, etc). See discussion around this here: http://serverfault.com/questions/760552/how-to-use-automatic-restart-with-jenkins-on-systemd

      Details of how provide both systemd unit file and SysV init file are detailed here:
      https://wiki.debian.org/Teams/pkg-systemd/Packaging

      This should be applicable to all distro, and systemd unit most likely the same across them all, as it's much more standardised than each distros SysV init infrastructure.

      https://github.com/jenkinsci/packaging

        Attachments

          Activity

          Hide
          axmetishe Eugene Ahmethanov added a comment - - edited

          I'll leave the unit template here for Jenkins within multi-instance tomcat installation, maybe this will be helpful.

          Only one thing - the internal restart commands like safeRestart or restart cause service to be unavailable since restart command is not correct in such case.

          #/lib/systemd/system/tomcat@.service 
          [Unit]
          Description=Apache Tomcat service for "%i"
          After=syslog.target network-online.target
          
          [Service]
          SyslogIdentifier=%i
          
          User=%i
          Group=%i
          PermissionsStartOnly=true
          
          EnvironmentFile=-/etc/sysconfig/%i
          Environment='CATALINA_PID=$MAINPID'
          
          ExecStartPre=/bin/bash -c 'systemctl set-environment JAVA_HOME=$(readlink -f /usr/bin/java | sed "s:/bin/java::")'
          ExecStartPre=/bin/bash -c 'systemctl set-environment CATALINA_HOME=$(readlink -f /usr/bin/tomcat)'
          
          ExecStart=@/usr/bin/java \
          $JAVA_OPTS \
          $JMX_OPTS \
          $INSTANCE_OPTS \
          $CATALINA_OPTS \
          -Djava.endorsed.dirs=${CATALINA_HOME}/endorsed \
          -Djava.io.tmpdir=${CATALINA_BASE}/temp \
          -Dcatalina.base=${CATALINA_BASE} \
          -Dcatalina.home=${CATALINA_HOME} \
          -classpath ${CATALINA_HOME}/bin/bootstrap.jar:${CATALINA_HOME}/bin/tomcat-juli.jar \
          org.apache.catalina.startup.Bootstrap start
          
          SuccessExitStatus=143
          
          [Install]
          WantedBy=multi-user.target
          Alias=%i.service
          
          

          UPD:

          Example config file for tomcat@jenkins instance:

          #/etc/sysconfig/jenkins
          
          CATALINA_BASE="/opt/jenkins/app"
          CATALINA_OPTS="-Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager"
          JAVA_OPTS="-Xms189M -Xmx1514M -XX:MaxDirectMemorySize=378M -XX:-UseConcMarkSweepGC -XX:+UseSerialGC"
          JMX_OPTS=""
          INSTANCE_OPTS="-Djava.net.preferIPv4Stack=true -Djava.net.preferIPv4Addresses=true -Djenkins.install.runSetupWizard=false"
          JENKINS_HOME="/opt/jenkins/data"
          

           

          Regards.

          Show
          axmetishe Eugene Ahmethanov added a comment - - edited I'll leave the unit template here for Jenkins within multi-instance tomcat installation, maybe this will be helpful. Only one thing - the internal restart commands like safeRestart or restart cause service to be unavailable since restart command is not correct in such case. #/lib/systemd/system/tomcat@.service [Unit] Description=Apache Tomcat service for "%i" After=syslog.target network-online.target [Service] SyslogIdentifier=%i User=%i Group=%i PermissionsStartOnly= true EnvironmentFile=-/etc/sysconfig/%i Environment= 'CATALINA_PID=$MAINPID' ExecStartPre=/bin/bash -c 'systemctl set-environment JAVA_HOME=$(readlink -f /usr/bin/java | sed "s:/bin/java::" )' ExecStartPre=/bin/bash -c 'systemctl set-environment CATALINA_HOME=$(readlink -f /usr/bin/tomcat)' ExecStart=@/usr/bin/java \ $JAVA_OPTS \ $JMX_OPTS \ $INSTANCE_OPTS \ $CATALINA_OPTS \ -Djava.endorsed.dirs=${CATALINA_HOME}/endorsed \ -Djava.io.tmpdir=${CATALINA_BASE}/temp \ -Dcatalina.base=${CATALINA_BASE} \ -Dcatalina.home=${CATALINA_HOME} \ -classpath ${CATALINA_HOME}/bin/bootstrap.jar:${CATALINA_HOME}/bin/tomcat-juli.jar \ org.apache.catalina.startup.Bootstrap start SuccessExitStatus=143 [Install] WantedBy=multi-user.target Alias=%i.service UPD: Example config file for tomcat@jenkins instance: #/etc/sysconfig/jenkins CATALINA_BASE= "/opt/jenkins/app" CATALINA_OPTS= "-Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager" JAVA_OPTS= "-Xms189M -Xmx1514M -XX:MaxDirectMemorySize=378M -XX:-UseConcMarkSweepGC -XX:+UseSerialGC" JMX_OPTS="" INSTANCE_OPTS= "-Djava.net.preferIPv4Stack= true -Djava.net.preferIPv4Addresses= true -Djenkins.install.runSetupWizard= false " JENKINS_HOME= "/opt/jenkins/data"   Regards.

            People

            • Assignee:
              kohsuke Kohsuke Kawaguchi
              Reporter:
              nickbrown Nicholas Brown
            • Votes:
              7 Vote for this issue
              Watchers:
              10 Start watching this issue

              Dates

              • Created:
                Updated: