版本:linux Centos6.7测试成功
1、进入脚本地址
cd /etc/init.d/
2、编辑tomcat启动脚本
vim tomcat
3、写脚本
#!/bin/sh
# chkconfig: 345 99 10
# description: Auto-starts tomcat
# /etc/init.d/tomcat
# Tomcat auto-start
# Source function library.
#. /etc/init.d/functions
# source networking configuration.
#. /etc/sysconfig/network
RETVAL=0
export JRE_HOME=/usr/jre1.7.0_22 //如果是使用jdk,则改为:JAVA_HOME=xxx即可
export CATALINA_HOME=/usr/tomcat7 //tomcat目录
export CATALINA_BASE=/usr/tomcat7
start()
{
if [ -f $CATALINA_HOME/bin/startup.sh ];
then
echo $"Starting Tomcat"
$CATALINA_HOME/bin/startup.sh
RETVAL=$?
echo " OK"
return $RETVAL
fi
}
stop()
{
if [ -f $CATALINA_HOME/bin/shutdown.sh ];
then
echo $"Stopping Tomcat"
$CATALINA_HOME/bin/shutdown.sh
RETVAL=$?
sleep 1
ps -fwwu tomcat | grep apache-tomcat|grep -v grep | grep -v PID | awk '{print $2}'|xargs kill -9
echo " OK"
# [ $RETVAL -eq 0 ] && rm -f /var/lock/...
return $RETVAL
fi
}
case "$1" in
start)
start
;;
stop)
stop
;;
restart)
echo $"Restaring Tomcat"
$0 stop
sleep 1
$0 start
;;
*)
echo $"Usage: $0 {start|stop|restart}"
exit 1
;;
esacls
exit $RETVAL
4、设置权限
chmod +x /etc/init.d/tomcat
5、查看启动顺序
cd /etc/rc2.d/
6、设定一下顺序,用不着
ln -s /etc/init.d/tomcat /etc/rc2.d/S16Tomcat
7、添加服务
chkconfig –add tomcat //add前面是2个 - ,展示成1个了。
8、重启查看是否启动
ps -ef |grep tomcat
不用重启的办法:
9、开启tomcat系统服务
chkconfig tomcat on
10、启动tomcat服务
serice tomcat start