tomcat8 configures boot under CentOS 7.5

Keywords: Tomcat Java network shell

This article references This article

1, Create a new file tomcat under / etc/init.d, and add the following content:

#!/bin/sh
# chkconfig: 345 99 10
# description: Auto-starts tomcat
# /etc/init.d/tomcatd
# Tomcat auto-start
# Source function library.
#. /etc/init.d/functions
# source networking configuration.
#. /etc/sysconfig/network
RETVAL=0
export JAVA_HOME=/usr/java/jdk1.7.0_60 #Change here to the actual location
export JRE_HOME=/usr/java/jdk1.7.0_60/jre #Change here to the actual location
export CATALINA_HOME=/usr/local/tomcat #Change here to the actual location
export CATALINA_BASE=/usr/local/tomcat #Change here to the actual location
start()
{
        if [ -f $CATALINA_HOME/bin/startup.sh ];
          then
            echo $"Starting Tomcat"
                $CATALINA_HOME/bin/startup.sh
            RETVAL=$?
            echo " OK"
            return $RETVAL
        fi
}
stop()
{
        if [ -f $CATALINA_HOME/bin/shutdown.sh ];
          then
            echo $"Stopping Tomcat"
                $CATALINA_HOME/bin/shutdown.sh
            RETVAL=$?
            sleep 1
            ps -fwwu root | grep tomcat|grep -v grep | grep -v PID | awk '{print $2}'|xargs kill -9
            echo " OK"
            # [ $RETVAL -eq 0 ] && rm -f /var/lock/...
            return $RETVAL
        fi
}

case "$1" in
 start) 
        start
        ;;
 stop)  
        stop
        ;;

 restart)
         echo $"Restaring Tomcat"
         $0 stop
         sleep 1
         $0 start
         ;;
 *)
        echo $"Usage: $0 {start|stop|restart}"
        exit 1
        ;;
esac
exit $RETVAL

Note that you need to change the location of the relevant environment variables in the script

2, Add executable permissions for the script you just created

chmod +x /etc/init.d/tomcat

3, Mount
Connect the link of the shell file to the directory / etc / RC2. D /. The numbers in / etc/rcX.d / directory of linux represent different run level s when starting up, that is, the order of starting. Ubuntu 9.10 has six levels of 0-5, which can't be connected to other directories at will. Maybe some libraries required by Tomcat have not been loaded when the program in that directory starts up. Use ln command to link Tomcat in the past: sudo ln -s /etc/init.d/tomcat /etc/rc2.d/S16Tomcat. The naming rules in the rcX.d directory are very particular. They may start with s or K, and the numbers after them represent their starting order. See the Readme files in their respective directories in detail.

ln -s /etc/init.d/tomcat /etc/rc2.d/S16Tomcat

4, Start up

chkconfig --add tomcat

At this point, you can start tomcat with the command

service tomcat start
service tomcat stop
service tomcat restart

Posted by PLaT on Sun, 03 May 2020 09:54:31 -0700