SUSE Linux does not have rc.local
1. Create a start/stop script file.
Through the following script, you can make Tomcat run in Service mode.
#!/bin/bash # chkconfig: 2345 10 90 # description: Starts and Stops the Tomcat daemon. TOMCAT_HOME=/usr/local/apache-tomcat-5.5.12 TOMCAT_START=$TOMCAT_HOME/bin/startup.sh TOMCAT_STOP=$TOMCAT_HOME/bin/shutdown.sh # necessary environment variables export CATALINA_HOME=$TOMCAT_HOME export JAVA_HOME=/usr/java/jdk1.5.0_05 # source function library. ./etc/rc.d/init.d/functions # source networking configuration. ./etc/sysconfig/network # check that networking is up. [ "${NETWORKING}" = "no" ] && exit 0 # check for tomcat script if [ ! -f $TOMCAT_HOME/bin/catalina.sh ] then echo "Tomcat not validable..." exit fi start(){ echo -n "Starting Tomcat: " daemon $TOMCAT_START echo touch /var/lock/subsys/tomcat } stop(){ echo -n ___FCKpd___0quot;Shutting down Tomcat: " daemon $TOMCAT_STOP rm -f /var/lock/subsys/tomcat.pid echo } restart(){ stop start } status(){ ps ax --width=1000 | grep "[o]rg.apache.catalina.startup.Bootstrap start" | awk '{printf $1 " "}' | wc | awk '{print $2}' > /tmp/tomcat_process_count.txt read line < /tmp/tomcat_process_count.txt if [ $line -gt 0 ]; then echo -n "tomcat ( pid " ps ax --width=1000 | grep "org.apache.catalina.startup.Bootstrap start" | awk '{printf $1 " "}' echo -n ") is running..." echo else echo "Tomcat is stopped" fi } case "$1" in start) start ;; stop) stop ;; restart) stop sleep 3 start ;; status) status ;; *) echo "Usage: tomcatd {start|stop|restart|status}" exit 1 esac exit 0 |
2. Save and set the script file.
Save the above script file in /etc/init.d and name it tomcat;
set the file attributes of tomcat
#chmod a+x tomcat
3. Set the service run level and
finally use chkconfig to set the service Run
#chkconfig --add tomcat
Note:
In the first two lines of comment statements in the tomcat file, you need to include chkconfig and description (make sure not to spell mistakes,), otherwise when executing "chkconfig --add tomcat", it will An error message "The tomcat service does not support chkconfig" appears.
The chkconfig line indicates the default startup run level and the start and stop priorities. If the service does not start at any run level by default, use - instead of the run level. In tomcat, it means that the script is started in run levels 2, 3, 4, and 5, with a start priority of 10 and a stop priority of 90.
The description line describes the service and can be commented with "" across lines.