You Are Here : Home » , » [How To] Automatically start Tomcat Service on boot in

[How To] Automatically start Tomcat Service on boot in

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.

$ vi /etc/rc.d/init.d/tomcat
----------------------------------------
#!/bin/sh
#
# Startup script for Tomcat Servlet Engine
#
# chkconfig: 345 86 14
# description: Tomcat Servlet Engine
# processname: tomcat

### BEGIN INIT INFO
# Provides: tomcat
# Required-Start: $remote_fs $syslog
# Required-Stop: $remote_fs $syslog
# Default-Start: 3 4 5
# Default-Stop: 0 1 2 6
# Short Description: Tomcat Servlet Engine
# Description: Tomcat Servlet Engine
### END INIT INFO
export CATALINA_HOME=/usr/share/tomcat
PATH=$PATH:/usr/java/jdk1.7.0_67/bin
start() {
 sh $CATALINA_HOME/bin/startup.sh
}
stop() {
 sh $CATALINA_HOME/bin/shutdown.sh
}
case $1 in
  start|stop) $1;;
  restart) stop; start;;
  *) echo "Run as $0 "; exit 1;;
esac
----------------------------------------
$ chmod +x /etc/init.d/tomcat
$ chkconfig tomcat on
Last but not least, depending on your OS make sure Tomcat service starts on server boot. Hope this helps!

1 comments:

Copyright © Am I a developer?. From Do Viet Kien.

Scroll to top