Configure Tomcat as a deamon on Linux
Since I keep on forgetting how to do this I decided to put this on my blog to make it easier for me and other people that have the same issue as me. It's pretty simple actually but yesterday I caught myself forgetting how it needs to be done. Basically you need to follow to following steps to successfully.
Step 1 - Creating startup deamon file
You can take the following file and adjust it accordingly. You have to create this file in /etc/init.d/.
Step 2 - Register your deamon
To register your deamon you can use chkconfig. This will make sure your deamon will be started up on boot and enables you to use the following command to start and stop your tomcat instance.
To start:
To stop:
To do the magic you should execute the following command:
Now your done :-)
Step 1 - Creating startup deamon file
You can take the following file and adjust it accordingly. You have to create this file in /etc/init.d/.
#Jenkins startup script
#!/bin/sh -e
#Jenkins startup script
#chkconfig: 2345 80 05
#description: Jenkins CI
# Define some variables
# Name of app
APP=Jenkins
# Name of the user to run as
USER=tomcat
# Location of application's bin directory
BASE=/var/tomcat/instances/jenkins
# Location of Java JDK
export JAVA_HOME=/opt/java/jdk1.6.0_11
case "$1" in
# Start command
start)
echo "Starting $APP"
/bin/su -m $USER -c "cd $BASE/logs && $BASE/bin/startup.sh &> /dev/null"
;;
# Stop command
stop)
echo "Stopping $APP"
/bin/su -m $USER -c "$BASE/bin/shutdown.sh &> /dev/null"
echo "$APP stopped successfully"
;;
# Restart command
restart)
$0 stop
sleep 5
$0 start
;;
*)
echo "Usage: /etc/init.d/$APP {start|restart|stop}"
exit 1
;;
esac
exit 0
Step 2 - Register your deamon
To register your deamon you can use chkconfig. This will make sure your deamon will be started up on boot and enables you to use the following command to start and stop your tomcat instance.
To start:
service jenkins start
To stop:
service jenkins stop
To do the magic you should execute the following command:
chkconfig jenkins --add
Now your done :-)
Comments
Post a Comment