If you are using the core version of Apache Tomcat and would like auto-start it on Linux here are the simple steps. I assume that you already have a running Apache Tomcat and know how to navigate to the terminal and have necessary system permission to proceed with this tutorial. Depending on the distribution that you are using you may need to find a specific location for the configuration or init.d folder.
1. Start by creating startup script into folder /etc/init.d/ or /etc/rc.d depending on what Linux distribution you are using.
$sudo vi tomcat
2. Enter the following scripts inside tomcat file
#!/bin/bash # # tomcat # # chkconfig: 35 # description: Start up the Tomcat servlet engine. # processname: tomcat # /etc/init.d/tomcat RETVAL=$? CATALINA_HOME="/opt/apache-tomcat-8.5.30" case "$1" in start) if [ -f $CATALINA_HOME/bin/startup.sh ]; then echo $"Starting Tomcat" $CATALINA_HOME/bin/startup.sh fi ;; stop) if [ -f $CATALINA_HOME/bin/shutdown.sh ]; then echo $"Stopping Tomcat" $CATALINA_HOME/bin/shutdown.sh fi ;; *) echo $"Usage: $0 {start|stop}" exit 1 ;; esac exit $RETVAL
NOTE
You will need to set the CATALINA_HOME and point it to the location where you deploy your Apache Tomcat.
Example:
CATALINA_HOME="/opt/apache-tomcat-8.5.30"
3. In this tutorial, we will create a symbolic link in Runlevel 3
$cd /etc/init.d/rc5.d/ $sudo ln -s ../init.d/tomcat S01tomcat $sudo ln -s ../init.d/tomcat K01tomcat
In case you’re wondering, what S or K means: S is to start the application and K stands for to kill or shutdown the application. The number denotes the order. There are a lot of articles already available on the Internet about Linux Runlevel. You can check out Linux Runlevels Explained and Understanding init scripts
Distribution Notes
SLES 11 SP4
In SLES11, once you created the files tomcat1 and tomcat2 inside init.d folder you don’t need to create the symbolic link manually. Instead, execute the following command
$chkconfig --set tomcat1 on $chkconfig --set tomcat2 on
To verify type the following code
$chkconfig
The output should look like this.
