Setting Up Start of Apache Tomcat as a Linux Service

To avoid starting Apache Tomcat every time after manual restarting of the operating system, one can set up automatic start of Apache Tomcat as a service. It is relevant if Apache Tomcat was downloaded as an archive and not installed from the repository. Execute the following operations:

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

  2. Edit the tomcat file to specify proper 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 specify name of the created user for Tomcat for the TOMCAT_USER parameter. Use the example data to get the following result:

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 /etc/init.d/ folder by executing the commands:

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:

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 System > Administrator > Services main menu item. In the dialog box that opens select Tomcat in the list of services and click the Enable button. Execute the command:

sudo chkconfig tomcat on

  1. Start Apache Tomcat by executing the command:

sudo service tomcat start

See also:

Advanced Web Application Settings