If you need to automatically start/stop Tomcat each time you start/stop/reboot your Linux server, you can do so by creating a start/stop script under the /etc/init.d directory.

The sample script below is called /etc/init.d/tomcat and runs Tomcat as a user called “tomcat” – because most likely you do not want Tomcat to run as root.

case "$1" in
    echo "Starting tomcat"
    su tomcat -c "export JAVA_HOME=/web/java;/web/tomcat/bin/startup.sh"
    echo "Stopping tomcat"
    su tomcat -c "export JAVA_HOME=/web/java;/web/tomcat/bin/shutdown.sh"
    echo "Usage: /etc/init.d/tomcat {start|stop}"
    exit 1
exit 0

After you create the script, you need to set its attributes:
sudo chmod 755 /etc/init.d/tomcat

And then create all the appropriate links to it:
sudo update-rc.d tomcat defaults

If you need to remove the links again (but keep the script), use the following command:
sudo update-rc.d -f tomcat remove

Leave a Reply

Your email address will not be published. Required fields are marked *

This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

The reCAPTCHA verification period has expired. Please reload the page.