Running Tomcat as a service on Debian

Posted on 22-01-2013 08:09 by graham
This tutorial show how to configure Apache Tomcat server to run as a service on Debian Linux and start automatically on system reboot.

Creating a start-up script


First we need to create a file that will fire our service. Go to /etc/init.d and create a file called tomcat. The name of the file can be different, but it has to be identical with the name of the service.

The script looks like this:
/etc/init.d/tomcat
#Tomcat auto-start
#description: Auto-starts tomcat
#processname: tomcat
#pidfile: /var/run/tomcat.pid

#this path should point to your JAVA_HOME Directory
export JAVA_HOME=/usr/lib/jvm/java-6-openjdk-amd64
case $1 in

start)
sh /opt/tomcat/bin/startup.sh
;;

stop)
sh /opt/tomcat/bin/shutdown.sh
;;

restart)
sh /opt/tomcat/bin/shutdown.sh
sh /opt/tomcat/bin/startup.sh
;;
esac

exit 0

This example assumes that you have Tomcat installed in /opt/tomcat, and that your Java home directory is /usr/lib/jvm/java-6-openjdk-amd64.

Setting rights for the start-up script


For the script to be executed, it has to be assigned proper rights:
chmod 755 /etc/init.d/tomcat


Setting Tomcat to run as service and start on reboot


Just run:
update-rc.d tomcat defaults

Start Tomcat manually


The service will start automatically when the system reboots, but if you want to run it manually, you can call:
/etc/init.d/tomcat start
Comments

 

Add comment

Has this tutorial been helpful to you? Or do you see anything wrong? We appreciate your opinion!
Your comment:
Show formatting hints
HTML is disallowed, but in your text you can use the following markup
  • [code][/code] for a block of code
  • [tt][/tt] for inline code
  • [link]link href|link anchor[/link] for links
  • [b][/b] for bold text
Email:
+ Ask a question
If you have a technical question related to programming and computers, ask it here. Other users will help you solve it!
Unanswered questions
Share your knowledge by helping others solve their problems