1. 编写服务脚本
[root@tomcat ~]# cd /etc/init.d/
[root@tomcat /etc/init.d]# vim tomcat
#!/bin/bash
#chkconfig:35 68 78 # 启动级别 开机顺序 关闭顺序
TOMCAT_HOME=/usr/local/tomcat #tomcat的安装目录
TOMCAT_BIN=$TOMCAT_HOME/bin #管理tomcat的脚本位置
start(){
$TOMCAT_BIN/startup.sh
}
stop(){
$TOMCAT_BIN/shutdown.sh
}
restart(){
stop
start
}
configtest(){
$TOMCAT_BIN/configtest.sh
}
status(){
if [ -f '/var/run/tomcat.pid' ];then
echo 'tomcat is running'
else
echo 'tomcat is stop'
fi
}
case "$1" in
start)
start;;
stop)
stop;;
restart)
restart;;
configtest)
configtest;;
status)
status;;
*)
echo"{start|stop|configtest|status}"
esac
[root@tomcat /usr/local/tomcat/bin]# vim catalina.sh

2. 测试脚本




3. 添加开机自启
[root@tomcat ~]# chkconfig --add tomcat
[root@tomcat ~]# reboot
