Blog Archive

Linux Centos Automatically Start Apache Tomcat server on boot

This article assumes that you have already installed the Apache Tomcat Server on your Linux Centos machine. If you need help with your with Apache Tomcat Setup then please click on the Link below.
Install Apache Tomcat Server on Linux Centos 

Step 1: Create a file named tomcat6 in your /etc/init.d directory

$ cd /etc/init.d
$ gedit tomcat6

Step 2: Copy the following script and save the file

# chkconfig: 2345 80 20
# Description: Tomcat Server basic start/shutdown script
# /etc/init.d/tomcat6 -- startup script for the Tomcat 6 servlet engine


start() {
 echo -n "Starting tomcat6: "
 echo "done."

stop() {
 echo -n "Shutting down tomcat6: "
 echo "done."

case "$1" in


 sleep 10

 echo "Usage: $0 {start|stop|restart}"

exit 0

Change the settings for the chkconfig based on your requirements. In a scenario where Apache Web server is in the front of Tomcat server with MySQL database usually the startup sequence should be MySQL then Tomcat and Apache Web Server in last. Also make sure you change the TOMCAT_HOME, START_TOMCAT and STOP_TOMCAT variables based on your Tomcat Install.

Step 3: Update the file permissions to make it executable by any user

$ chmod 755 tomcat6

Step 4: Make sure you have chkconfig command installed

$ chkconfig --helpotherwise just install it
$ sudo apt-get install chkconfig


Step 5: Run chkconfig command to add the script to the startup services

$ chkconfig --add tomcat6

Basically the chkconfig command automatically adds the symbolic links for starting and stopping the service based on the paramaters passed to it. Here is the list of links created from the above link. You can run the find command to check.
$ find . -name "*tomcat6"

Response from the above command ...

Step 6: Make sure scripts got added to the startup services

Type the following command on the Terminal
$ chkconfig --list tomcat6
Response should be something like this
tomcat6         0:off   1:off   2:on    3:on    4:on    5:on    6:off

Step 7: Verify your service is working

To start the Tomcat server
$ service tomcat start
To stop the Tomcat server
$ service tomcat stop