Source

Portfolio / initscripts / jenkins

Full commit
#!/bin/sh
#
# Startup script for the Jenkins Continuous Integration server
# (via Jakarta Tomcat Java Servlets and JSP server)
## description: Jakarta Tomcat Java Servlets and JSP server
# processname: tomcat
# pidfile: /var/run/tomcat.pid

### BEGIN INIT INFO
# Provides:          jenkins
# Required-Start:    $local_fs $remote_fs $network $syslog $named
# Required-Stop:     $local_fs $remote_fs $network $syslog $named
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# X-Interactive:     true
# Short-Description: Start/stop tomcat with jenkins as root application 
### END INIT INFO


# Set Tomcat environment.
JENKINS_USER=jenkins
LOCKFILE=/home/jenkins/jenkins.pid
export PATH=/usr/local/bin:$PATH
export HOME=/home/jenkins/.jenkins
export JAVA_HOME=/opt/java/latest
export JENKINS_BASEDIR=$HOME/
export TOMCAT_HOME=/home/jenkins/tomcat/latest
export CATALINA_HOME=$TOMCAT_HOME
export CATALINA_PID=/home/jenkins/tomcat.pid
export CATALINA_OPTS="-DJENKINS_HOME=$JENKINS_BASEDIR -Xmx512m -Djava.awt.headless=true"

[ -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/bash $JENKINS_USER -c "$CATALINA_HOME/bin/catalina.sh start"
        RETVAL=$?
        echo
        [ $RETVAL = 0 ] && touch $LOCKFILE
    ;;
    stop)
        # Stop daemons.
        echo -n "Shutting down Tomcat: "
        su -p -s /bin/bash $JENKINS_USER -c "$CATALINA_HOME/bin/catalina.sh stop"
        RETVAL=$?
        echo
        [ $RETVAL = 0 ] && rm -f $LOCKFILE
    ;;
    restart)
        $0 stop
        $0 start
    ;;
    condrestart)
        [ -e $LOCKFILE ] && $0 restart
    ;;
    status)
        if [ -e $LOCKFILE ]; then
            echo "Jenkins is running."
        else
            echo "Jenkins is not running."
        fi
    ;;
    *)
        echo "Usage: $0 {start|stop|restart|status}"
        exit 1
    esac

exit 0