Linux startup script
- JenkinsLinuxStartupScript - a simple shell script enabling to start, stop, and restart Jenkins from
daemonize is a very simple program that allows you to launch Jenkins (or any arbitrary program) as a daemon. For people without much Unix experience, this is recommended.
daemontools is another possibility. This is more complicated to set up and it doesn't really follow the normal Unix convention, but it offers daemon control (like start/stop), log capturing, as well as automatic restart when the service dies.
Adjust the above for your need – it is the part of my init scripts.
Java Service Wrapper
This example will install a Jenkins instance in /home/jenkins on a debian machine. The Jenkins configuration is stored in /home/jenkins/data. Jenkins will be running on port 8070 and as the jenkins user.
- Select and download a JSW package from the JSW wrapper download page.
- Unpack the package into the /home/jenkins path.
- Create /home/jenkins/tmp as the temporary directory for JSW.
- Download the
jenkins.warfile into /home/jenkins/lib.
- If you have plugins that you would like to use, download them into /home/jenkins/data/plugins.
- Copy the /home/jenkins/src/conf/wrapper.conf.in to /home/jenkins/conf/wrapper.conf and change the below configuration properties in the file.
- Verify the wrapper configuration by starting Jenkins through /home/jenkins/bin/testwrapper console. Jenkins should be accessible through http://localhost:8070, if not check the console output for errors.
- Copy the /home/jenkins/src/bin/sh.script.in to /etc/init.d/jenkins and change the below configuration properties in the file.
- Verify installation by starting the daemon through /etc/init.d/jenkins start. Make sure that /etc/init.d/jenkins has the correct permissions; normally 755 is ok for this.
Please feel free to add your suggestion here
Linux service - systemd
This is another way to start Jenkins as Linux service, also on system startup. I tested it on Fedora distribution, but it should work with other too. It needs some minimal experience with Linux superuser (sudo) and preferably basic Vi commands.
- Download jenkins.war file to any convenient destination, eg. /home/jenkins_user
- Create service file /etc/systemd/system/jenkins.service and paste following there:
- Reload service manager: systemctl daemon-reload
- That's it! Now manage the service:
- If anything goes wrong, use journalctl command (and scroll to bottom) to see any error messages.
- You may want to redirect or suppress Jenkins output, otherwise you can kill Journal log. Change jenkins.helper to eg. java -jar /home/jenkins_user/jenkins.war > /dev/null &
For further systemd configuration like auto restart, please refer to http://www.freedesktop.org/software/systemd/man/systemd.service.html