Extending the basic setup
When you exit from the command prompt or shell that started the process that we looked at previously, the Jenkins instance will stop with the exit, so for anything beyond a very quick ad hoc test, some form of initialization or process management script is highly recommended. Such a script can also be easily tailored to perform a few "nice to have" functions for you, for example, things such as these:
- Starting up at system boot time
- Catering to
stop|start|restart|status
requests - Redirecting console output to a log file so that you can monitor it for issues
- Running as a background/daemon process
- Running on a nonstandard port by setting the
--httpPort=
parameter, in cases where port8080
is already used by another application - Binding to a specific network interface, rather than the default
0.0.0.0
value using the--httpListenAddress=
option
This Ubuntu-based example script from the home page demonstrates many of the previously mentioned features of Jenkins that is running under Tomcat. The script can be found at https://wiki.jenkins-ci.org/display/JENKINS/JenkinsLinuxStartupScript and is as follows:
#!/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
Note that the http://jenkins-ci.org/ home page also hosts Native Installers for many popular operating systems under the Native packages column. These pages provide download links and installation instructions for each OS.
You may want to look at running Jenkins in a J2EE container too, which can often lead to a more seamless fit with your existing software stack and architecture. This may mean that you will inherit additional benefits, such as the container's logging, authentication, authorization, or resilience. Jenkins can be run with many popular J2EE compatible containers, including the following:
- WebSphere
- WebLogic
- Tomcat
- JBoss
- Jetty
- Jonas
There are more init
script examples and detailed installation instructions readily available on the Web, which should cover any combination of operating system and container setup. The point of this is that you should be able to set up Jenkins to suit your environment and preferences.
For the purposes of this book, we will assume that Jenkins is being run directly from the command line on the local host. If you are using a J2EE container to host the application or running the application on a remote host, the only difference you will notice is that you may need to perform additional admin and deployment steps.