The Apache Tomcat is widely use in the Application servers. Sometimes, naive users are not aware of starting/stopping tomcat service. Also, Apache Tomcat service auto start is required in case of server reboot.
To achieve this, Apache Tomcat should be added in the desired runlevel with a script, as explained in the below steps.
1) Create script name tomcat containing following code
#!/bin/sh # Created by: Abhijit Sandhan # Purpose: Start or stop the Tomcat service. # Check the path of Tomcat and set enviorment variables as follows in the .bashrc profile # export CATALINA_HOME="/usr/local/tomcat7/apache-tomcat-7.0.37" # export CATALINA_BASE="/usr/local/tomcat7/apache-tomcat-7.0.37" # export JAVA_HOME="/usr/local/java/jdk1.7.0_17" export JAVA_HOME=/usr/local/java/jdk1.7.0_17 case $1 in start) cd /usr/local/tomcat7/apache-tomcat-7.0.37/bin/ ./startup.sh ;; stop) cd /usr/local/tomcat7/apache-tomcat-7.0.37bin/ ./shutdown.sh ;; restart) cd /usr/local/tomcat7/apache-tomcat-7.0.37/bin/ ./shutdown.sh cd /usr/local/tomcat7/apache-tomcat-7.0.37/bin/ ./startup.sh ;; esac exit 0
Make sure to replace the tomcat, java directory paths & variables according to your server settings in the above script.
2) Copy the tomcat script under /etc/init.d directory.
3) Create symlinks to start/stop tomcat service for desired runlevel.
Example: For runlevel 2
sudo ln -s /etc/init.d/tomcat /etc/rc2.d/S99tomcat
4) Reboot the server to verify if following commands are working or not
Last but not least, depending on your OS make sure Tomcat service starts on server boot.
Hope this helps!