转:http://anxue071.blog.51cto.com/2750845/717119
一,脚本文件,编辑好后放在/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 java and 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/nohup_start.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.在tomcat目录下编辑nohup_startup.sh(启动)文件
rm -fr /usr/local/tomcat/bin/nohup.out
nohup /usr/local/tomcat/bin/catalina.sh run > /usr/local/tomcat/bin/nohup.out &
5.给nohup_startup.sh执行权限。