请把本文件放到 /etc/init.d,文件名为tomcat(或tomcat7)
然后在/etc/rc3.d/目录下,建立一个软连接: ln -s /etc/init.d/tomcat S95tomcat
然后自动启动并添加服务:
chkconfig --add tomcat
chkconfig tomcat on
# 脚本内容如下,并注意修改对应的目录!
#!/bin/bash
# description: Tomcat Start Stop Restart
# processname: tomcat
# chkconfig: 234 20 80
JAVA_HOME=/usr/java/jre1.7.0_45
export JAVA_HOME
PATH=$JAVA_HOME/bin:$PATH
export PATH
CATALINA_HOME=/var/lib/tomcat7
case $1 in
start)
sh $CATALINA_HOME/bin/startup.sh
;;
stop)
sh $CATALINA_HOME/bin/shutdown.sh
;;
restart)
sh $CATALINA_HOME/bin/shutdown.sh
sh $CATALINA_HOME/bin/startup.sh
;;
esac
exit 0