Setting Up Start of Apache Tomcat as a Linux Service

To avoid restarting Apache Tomcat manually at each system restart, Apache Tomcat startup can be set up as a service. The option is relevant if Apache Tomcat was downloaded as an archive and not installed from repository. Execute the following operations:

  1. Copy the tomcat file located in the folder with the installed Apache Tomcat to the home directory.

  2. Edit the tomcat file to specify required environment variables and user name for Tomcat:

nano ~/tomcat

  1. Change values of the CATALINA_HOME and CATALINA_BASE parameters to /opt/tomcat7/<Apache Tomcat 7 archive name>, and for TOMCAT_USER parameter specify name of user created for Tomcat. Using data from the example results in:

CATALINA_HOME=/opt/tomcat7/<Apache Tomcat 7 archive name>

CATALINA_BASE=/opt/tomcat7/<Apache Tomcat 7 archive name>

TOMCAT_USER=tomcat

  1. Move the tomcat file to the directory /etc/init.d/ by executing the commands in the terminal:

sudo cp tomcat /etc/init.d/

sudo chmod +x /etc/init.d/tomcat

  1. Add Apache Tomcat to the list of system services by executing the command in the terminal:

sudo -u tomcat /opt/tomcat7/<Apache Tomcat 7 archive name>/bin/catalina.sh stop

sudo chkconfig --add tomcat

  1. Enable the Tomcat service. To do this, open the list of services by selecting the main menu item System > Administrator > Services. In the dialog box that opens select Tomcat in the list of services and click the Enable button. Execute the following command in the terminal:

sudo chkconfig tomcat on

  1. Run Apache Tomcat by executing the command in the terminal:

sudo service tomcat start

See also:

Questions and Answers