一,脚本文件,编辑好后放在/etc/rc.d/init.d/下面
#!/bin/sh
#chkconfig: 2345 10 90
# description: Starts and Stops the Tomcat daemon.
#by jj
##############################################
#Startup script for Tomcat on Linux
#filename tomcat.sh
#Make sure the Javaand the tomcat installation path has been added to the PATH
JAVA_HOME=/usr/local/jdk #JDK安装目录
CATALINA_HOME=/usr/local/tomcat #tomcat安装目录
export JAVA_HOME
export CATALINA_HOME
###############################################
start_tomcat=$CATALINA_HOME/bin/startup.sh #tomcat启动文件
stop_tomcat=$CATALINA_HOME/bin/shutdown.sh #tomcat关闭文件
start() {
echo -n "Starting tomcat: "
${start_tomcat}
echo "tomcat start ok."
}
stop() {
echo -n "Shutting down tomcat: "
${stop_tomcat}
echo "tomcat stop ok."
}
# See how we were called
case "$1" in
start)
start
;;
stop)
stop
;;
restart)
stop
sleep 10
start
;;
*)
echo "Usage: $0 {start|stop|restart}"
esac
exit 0
二,后续服务:
1.给脚本权限:chmod 755 tomcat
2.添加到服务:chkconfig --add tomcat
3.开机启动项:chkconfig --level 345 tomcat on
4.好了,现在可以通过 service tomcat start 命令启动 Tomcat 了,关闭及重启服务的命令也类似,只是将 start 换成 stop 或 restart。