The Linux system installs Tomcat and configures Service to start and shut down
- 2021-08-31 09:47:42
- OfStack
Configure service startup and shutdown under Linux system
1. Under the command cd/etc/init. d folder
2. Then enter the vim editing interface by commanding vim tomcat
3. After using i key, now paste the following code into the editing interface
The shell script is as follows
#!/bin/bash
# This is the init script for starting up the
# Jakarta Tomcat server
#
# chkconfig: 345 91 10
# description: Starts and stops the Tomcat daemon.
#
# Source function library.
. /etc/rc.d/init.d/functions
# Get config.
. /etc/sysconfig/network
# Check that networking is up.
[ "${NETWORKING}" = "no" ] && exit 0
export JAVA_HOME=/usr/local/javaweb/jdk1.8.0_192 # Own jdk Installation directory
tomcat_home=/usr/local/tomcat/tomcat # Own tomcat Installation directory
startup=$tomcat_home/bin/startup.sh
shutdown=$tomcat_home/bin/shutdown.sh
start(){
echo -n "Starting Tomcat service:"
cd $tomcat_home
$startup
echo "tomcat is succeessfully started up"
}
stop(){
echo -n "Shutting down tomcat: "
cd $tomcat_home
$shutdown
echo "tomcat is succeessfully shut down."
}
status(){
numproc=`ps -ef | grep catalina | grep -v "grep catalina" | wc -l`
if [ $numproc -gt 0 ]; then
echo "Tomcat is running..."
else
echo "Tomcat is stopped..."
fi
}
restart(){
stop
start
}
# See how we were called.
case "$1" in
start)
start
;;
stop)
stop
;;
status)
status
;;
restart)
restart
;;
*)
echo $"Usage: $0 {start|stop|status|restart}"
exit 1
esac
(The file cannot be executed, execute this command.) Add permissions to the file so that the script file can be executed. The command is: chmod 755/etc/rc. d/init. d/tomcat
4. Add the file to the service queue
chkconfig --add tomcat
5. Check whether the tomcat file has been successfully added to the service list
chkconfig --list
6. Set the service to start automatically
chkconfig tomcat on
That concludes the summary