2

I have Jenkins running on a CentOS7 and it kind of crashes from time to time and I'd like to restart it automatically when this happens. Googleing a bit I've found that on Systemd you can use Restart=on-failure but the problem is that from what I see Jenkins does not use a service file.

If I do systemctl status jenkins.service I get:

● jenkins.service - LSB: Jenkins Continuous Integration Server
   Loaded: loaded (/etc/rc.d/init.d/jenkins)
   Active: active (running) since Mon 2016-02-29 17:30:08 UTC; 11min ago

So looks like it's still using init.d? Any idea how I can use this Restart=on-failure in this case?

2

As a total horrible kluge you could point systemd at the jenkins init script, as that script has a whole bunch of annoying "where's Java" and other code to figure out how to get jenkins up and running.

# cat /etc/systemd/system/jenkins.service
[Unit]
Description=Jenkins Server Daemon
Wants=network-online.target
After=network-online.target

[Service]
ExecStart=/etc/init.d/jenkins start
Restart=always
RestartSec=3
Type=forking

[Install]
WantedBy=multi-user.target
# systemctl enable jenkins.service

and then the service starts at reboot, is not listed by chkconfig --list, and restarts even if you kill -9 $thepid though ideally long-term a better option would be for the jenkins folk to include direct support for systemd in their RPM...

  • And if I add this how can I prevent it from starting twice? As right now it already starts automatically due to it having the script in init.d? (I installed it via yum install after adding their repo). Or just because I now create the jenkins.service systemd will use this instead and not run the init.d script also? – daniels Feb 29 '16 at 20:55
  • Did you run chkconfig --list before and after? When I did, systemd had magically removed the init entry on a test Centos 7 virt. – thrig Feb 29 '16 at 21:00
  • Just tested now and it works. After creating the .service file chkconfig --list does not display it anymore and it's also automatically restarted. Thanks. – daniels Feb 29 '16 at 23:26
1

I can offer systemd-file which is a modification of the code from the Jenkins Wiki:

[Unit]
Description=Jenkins Daemon

[Service]
SuccessExitStatus=143
ExecStart=/usr/bin/java -jar /usr/share/jenkins/jenkins.war --webroot=/var/cache/jenkins/war --httpPort=8081 --ajp13Port=-1
Environment="JENKINS_HOME=/data/jenkins"
User=jenkins

[Install]
WantedBy=multi-user.target

That works much better than the one from @thrig on Ubuntu 16.04 with Jenkins installed via apt. This way you don't need /etc/init.d/jenkins and /etc/default/jenkins anymore and also get the logs directly in journalctl.

0

Jenkins packages are still shipping with only a SysV init file, so systemd specific behaviours are not available. I raise a bug report to request that a systemd unit file is shipped in the packages. https://issues.jenkins-ci.org/browse/JENKINS-41218

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.