This is a startup script for Linux, and provides start/stop/restart/status functionality. This has been tested on Redhat, but should work on other Linuxes like Ubuntu or SuSE. You may need to change the environment variables at the top of the script to fit your system. This assumes that Jenkins is installed in /home/jenkins
, Tomcat is installed in /home/jenkins/apache-tomcat-6.0.18, and that JENKINS_HOME is /home/jenkins/jenkins-home
To install, on Ubuntu:
- Save the file to
/etc/init.d/jenkins
chmod a+x /etc/init.d/jenkins
update-rc.d jenkins defaults
#!/bin/sh # # Startup script for the Jenkins Continuous Integration server # (via Jakarta Tomcat Java Servlets and JSP server) # # chkconfig: - 85 15 # description: Jakarta Tomcat Java Servlets and JSP server # processname: jenkins # pidfile: /home/jenkins/jenkins-tomcat.pid # Set Tomcat environment. JENKINS_USER=jenkins LOCKFILE=/var/lock/jenkins export PATH=/usr/local/bin:$PATH export HOME=/home/jenkins export JAVA_HOME=/usr/lib/jvm/java-6-sun export JENKINS_BASEDIR=/home/jenkins export TOMCAT_HOME=$JENKINS_BASEDIR/apache-tomcat-6.0.18 export CATALINA_PID=$JENKINS_BASEDIR/jenkins-tomcat.pid export CATALINA_OPTS="-DJENKINS_HOME=$JENKINS_BASEDIR/jenkins-home -Xmx512m -Djava.awt.headless=true" # Source function library. . /etc/rc.d/init.d/functions [ -f $TOMCAT_HOME/bin/catalina.sh ] || exit 0 export PATH=$PATH:/usr/bin:/usr/local/bin # See how we were called. case "$1" in start) # Start daemon. echo -n "Starting Tomcat: " su -p -s /bin/sh $JENKINS_USER -c "$TOMCAT_HOME/bin/catalina.sh start" RETVAL=$? echo [ $RETVAL = 0 ] && touch $LOCKFILE ;; stop) # Stop daemons. echo -n "Shutting down Tomcat: " su -p -s /bin/sh $JENKINS_USER -c "$TOMCAT_HOME/bin/catalina.sh stop" RETVAL=$? echo [ $RETVAL = 0 ] && rm -f $LOCKFILE ;; restart) $0 stop $0 start ;; condrestart) [ -e $LOCKFILE ] && $0 restart ;; status) status -p $CATALINA_PID -l $(basename $LOCKFILE) jenkins ;; *) echo "Usage: $0 {start|stop|restart|status}" exit 1 esac exit 0
To install, on Red Hat
- Save the file to
/etc/init.d/jenkins
chmod a+x /etc/init.d/jenkins
chkconfig jenkins on
ntsysv
and see if the Jenkins service is turned on.