Auto Starting and Stopping Tomcat on Linux

Most of the time I install Apache Tomcat as a Tar file on Linux.

This works well when I just want to manually start and stop Tomcat from the command line.

However if you have installed Tomcat on a Amazon EC2 instance, then you its a good idea to automatically start and stop Tomcat on server starts and re-starts.

So, the following steps worked for on Ubuntu 12.04.

Create a start up and shutdown script for Tomcat

sudo nano /etc/init.d/tomcat

In the file you should enter the following commands ( except for the changes for your environment )

# Tomcat auto-start
#
# description: Auto-starts tomcat
# processname: tomcat
# pidfile: /var/run/tomcat.pid
export JAVA_HOME=<this is the folder where you have Java installed>
case $1 in
start)
        sh <this is where tomcat is installed>/startup.sh
        ;;
stop)
        sh <this is where tomcat is installed>/shutdown.sh
        ;;
restart)
        sh <this is where tomcat is installed>/shutdown.sh
        sh <this is where tomcat is installed>/startup.sh
        ;;
esac 
exit 0

Make the script executable.

sudo chmod 755 /etc/init.d/tomcat

Finally, link the script to the startup folders via a symbolic link.


sudo ln -s /etc/init.d/tomcat /etc/rc1.d/K99tomcat
sudo ln -s /etc/init.d/tomcat /etc/rc2.d/S99tomcat




Comments

Popular posts from this blog

Vaadin - GRID Component

Connecting a Vaadin SQL Container to a Combo Box

Vaadin and Google Maps