Starting Tomcat on Bootup in Ubuntu

I’m moving some of my operations to a Linux VPS soon so I can be as crazy with Tomcat and Java as I wanna be. The first thing to do in preparation is to make sure Tomcat fires up on server bootup.

There are two ways to go about it.

  1. Create a tomcat.conf Upstart Script and place it in /etc/init/
  2. Create a process named tomcat and place the script in /etc/init.d/

I started with an Upstart Script but that involves creating a new system user account, assign it to the www-data group and modify the permissions of the entire Tomcat installation to apache-tomcat:www-data. Too many potential gotchas with that, at least for me, so I went with creating a tomcat process.

Creating a process works for me because I simply download the latest Tomcat release, stick it in a utility directory and tomcat-8.x.x/bin/startup.sh to rock-n-roll. Below is my tomcat process script that goes in the Ubuntu/Mint /etc/init.d/ folder. It is based on the script from Developer’s Den. The difference here is we’re using the $CATALINA_HOME environment variable to startup and shutdown Tomcat.

# Tomcat auto-start
#
# description: Auto-starts tomcat
# processname: tomcat
# pidfile: /var/run/tomcat.pid

export JAVA_HOME=/usr/local/java/jdk1.8.0_05
export CATALINA_HOME=/ubuntuland/utils/apache-tomcat-8.0.8

case $1 in
start)
    sh $CATALINA_HOME/bin/startup.sh
    ;;
stop)
    sh $CATALINA_HOME/bin/shutdown.sh
    ;;
restart)
    sh $CATALINA_HOME/bin/shutdown.sh
    sh $CATALINA_HOME/bin/startup.sh
    ;;
esac
exit 0

After creating the script, complete the Developer’s Den post instructions on making the tomcat script executable and creating a symbolic link to the startup folders.

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

Now you’re ready to go Tomcat and Java crazy on your new VPS Host just like me!