[JIRA] (JENKINS-41218) Provide native systemd unit

107 views
Skip to first unread message

nickbroon@gmail.com (JIRA)

unread,
Jan 19, 2017, 10:17:02 AM1/19/17
to jenkinsc...@googlegroups.com
Nicholas Brown created an issue
 
Jenkins / Improvement JENKINS-41218
Provide native systemd unit
Issue Type: Improvement Improvement
Assignee: Kohsuke Kawaguchi
Components: packaging
Created: 2017/Jan/19 3:16 PM
Priority: Minor Minor
Reporter: Nicholas Brown

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

Add Comment Add Comment
 
This message was sent by Atlassian JIRA (v7.1.7#71011-sha1:2526d7c)
Atlassian logo

axmetishe+jenkins.io@gmail.com (JIRA)

unread,
Jan 15, 2019, 2:40:02 PM1/15/19
to jenkinsc...@googlegroups.com
Eugene Ahmethanov commented on Improvement JENKINS-41218
 
Re: Provide native systemd unit

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

Regards.

This message was sent by Atlassian Jira (v7.11.2#711002-sha1:fdc329d)

axmetishe+jenkins.io@gmail.com (JIRA)

unread,
Jan 15, 2019, 2:47:02 PM1/15/19
to jenkinsc...@googlegroups.com
Eugene Ahmethanov edited a comment on Improvement JENKINS-41218
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.
{code:java}
{code}
UPD:

Example config file for tomcat@jenkins instance:
{code:java}
#/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"
{code}
 

Regards.

ieugen@netdava.com (JIRA)

unread,
May 11, 2020, 1:51:03 AM5/11/20
to jenkinsc...@googlegroups.com

Hello,

What can I/we do to have this fix applied? Systemd has become the defacto service manager across major / all distributions.

There are new releases in Debian and RHEL that use systemd. There are great benefits to have apps managed by systemd.

It would be great to have this upstream. Even if it is disabled and we need to `systemctl enable ` it manually.

 

Looking forward for your feedback.

 

Thanks

This message was sent by Atlassian Jira (v7.13.12#713012-sha1:6e07c38)
Atlassian logo

dirk.heinrichs@recommind.com (JIRA)

unread,
May 11, 2020, 2:22:04 AM5/11/20
to jenkinsc...@googlegroups.com

The above is for running Jenkins in Tomcat, isn't it? It also seems to be RedHat specific (/etc/sysconfig). When running apps in Tomcat, one usually just need to start Tomcat itself, which in turn takes care of starting all the webapps deployed to it. So setting up a "tomcat@.service" for single webapps doesn't seem to be necessary at all (and also feels wrong given that this would mean to start one Tomcat instance for each webapp configured this way).

OTOH, this ticket is about a "native" systemd unit, which I think means: One that starts Jenkins standalone, just like the current sys-v init script does.

axmetishe+jenkins.io@gmail.com (JIRA)

unread,
May 11, 2020, 3:15:03 AM5/11/20
to jenkinsc...@googlegroups.com


The above is for running Jenkins in Tomcat, isn't it?

Yes. The example provided based on [Advanced Configuration - Multiple Tomcat Instances|https://tomcat.apache.org/tomcat-8.0-doc/RUNNING.txt] - e.g. single installation and "n" - Tomcat Server instances, which allow to run NOT multiple applications within single server(which is also possible by default), but multiple Tomcat Server instances.
This is widely used technique when you desire to split up different application servers but share binaries between them.
Unit template "tomcat@.service" follow the described flow above:

  1. Determines current default Tomcat binaries(configured via alternatives) directory and expose required variable 

  1. ExecStartPre=/bin/bash -c 'systemctl set-environment CATALINA_HOME=$(readlink -f /usr/bin/tomcat)'
  1. Retrieves server instance configuration(RedHat or Debian makes no difference here, just replace 'sysconfig' to 'default' on deb packaging stage)
    EnvironmentFile=-/etc/sysconfig/%i
  2. Starts dedicated Tomcat Instance for Jenkins

This kind of configuration provides flexibility on Servlet container configuration, protocols configuration used for proxy communication, simple server and java versions updates, and simplicity for multiple server configuration(dev/int/stage/prod instances) when you are on bare-metal/virtual machines.

So setting up a "tomcat@.service" for single webapps doesn't seem to be necessary at all

For the configuration when the single app should have its own server.

 

One that starts Jenkins standalone, just like the current sys-v init script does.

I'd left this advanced java app deployment configuration here for someone who tried to find systemd solution from the maintainers. Feel free to switch this unit to the internal winstone(jetty) servlet container used at Jenkins war/jar binaries.

Regards.

dirk.heinrichs@recommind.com (JIRA)

unread,
May 11, 2020, 4:25:03 AM5/11/20
to jenkinsc...@googlegroups.com

Eugene Ahmethanov, but still, this way of starting Jenkins should not be part of the Jenkins package, but the Tomcat one, right? Also, the "EnvironmentFile" entry is there for providing some kind of backwards compatibility with system v. In a pure systemd setup they shouldn't be used anymore as environment variables can be added directly via "Environment" entries. Customizations should then go into /etc/systemd/system/myservice.service.d/*.conf. This completely eliminates the need for ANY distribution specific files.

I'll try to write a native service file for standalone Jenkins, I already have one for starting swarm agents which I can use as a starting point...

axmetishe+jenkins.io@gmail.com (JIRA)

unread,
May 11, 2020, 4:44:04 AM5/11/20
to jenkinsc...@googlegroups.com


not be part of the Jenkins package, but the Tomcat one, right?

not Jenkins, nor Tomcat - environment specific configuration

 

Also, the "EnvironmentFile" entry is there for providing some kind of backwards compatibility with system v

wrong - this is not a backward compatibility level, but conscious way to pass basic deployment configuration instead of large unit file with tons of Environment definitions which will not be updated from place to place

 

In a pure systemd setup they shouldn't be used anymore as environment variables

wrong again - it's a just two different methods for environment configuration for 'pure' systemd setup

 

Customizations should then go into /etc/systemd/system/myservice.service.d/*.conf

customization will still be applied even using EnvironmentFile which is related to general configuration - https://www.freedesktop.org/software/systemd/man/systemd.exec.html

 

This completely eliminates the need for ANY distribution specific files

You will still have to do some customization with deb/rpm packaging at pre-inst/post-inst for example and string replacement will be the lesser problem

 

I'll try to write a native service file for standalone Jenkins, I already have one for starting swarm agents which I can use as a starting point

Glad to hear that.

 

Regards.

Reply all
Reply to author
Forward
0 new messages