a. Create a file
tomcat
in the /etc/init.d/ directory , the code is as follows:
# chkconfig: 345 91 10? # description: tomcat start and stop script # include function library . /etc/rc.d/init.d/functions # Get network configuration . /etc/sysconfig/network # Check if NETWORKING is "yes" [ "${NETWORKING}" = "no" ] && exit 0 # set variables # $TOMCAT points to the Tomcat installation directory TOMCAT=/usr/local/tomcat # $STARTUP points to Tomcat's startup script STARTUP=$TOMCAT/bin/startup.sh # $SHUTDOWN points to Tomcat's shutdown script SHUTDOWN=$TOMCAT/bin/shutdown.sh # Set the JAVA_HOME environment variable to point to the JDK installation directory export JAVA_HOME=/usr/local/jdk # start the service function start() { echo -n $"Starting Tomcat service: "? $STARTUP RETVAL=$? echo } # close the service function stop() { action $"Stopping Tomcat service: " $SHUTDOWN RETVAL=$? echo } # Call according to the parameter selection case "$1" in start) start ;; stop) stop ;; restart) stop start ;; *) echo $"Usage: $0 start|stop|restart" exit 1 esac exit 0b) Modify the access permissions of the tomcat file
chmod 4755 tomcat
c) Generate service
chkconfig --add tomcat
Well, now you can start Tomcat through the service tomcat start command. The commands for closing and restarting the service are similar, except that start is replaced by stop or restart.