linux服务器上每次都要跑到tomcat目录中bin启动服务,比较麻烦,可以将tomcat的启动添加至linux的service中。以下是个简单的示例,具体的shell脚本需要自己去完善。
1、编辑shell脚本。命名为tomcat.sh(你自己想叫啥就叫啥)。
#!/bin/bash
# chkconfig: 2345 10 90
#description: start and stop tomcat by service
export TOMCAT_HOME=/java/tomcat/
#start
start(){
echo -n "The fucking tomcat is starting...wait for a few minutes"
./$TOMCAT_HOME/bin.start.sh
echo
}
#stop
stop(){
echo -n "The mother fucker tomcat is shutting down "
./$TOMCAT_HOME/bin/shutdown.sh
echo
}
#restart
restart(){
stop
sleep 2
start
echo
}
case "$1" in
start)
start ;;
stop)
stop ;;
restart)
restart ;;
*)
echo "use tomcat {start|stop|restart}"
exit 1
esac
exit 0
注意:
第一行是服务的配置:
第一个数字是服务的运行级,2345表明这个服务的运行级是2、3、4和5级(Linux的运行级为0到6);
第二个数字是启动优先级,数值从0到99;
第三个数是停止优先级,数值也是从0到99。第二行是对服务的描述
- 其中的TOMCAT_HOME就是linux服务器上tomcat的位置。
2、将脚本移动到/etc/init.d/目录下。
3、注意给tomcat.sh添加可操作的权限。
#chmod 755 tomcat.sh
4、添加服务。
#chkconfig --add tomcat.sh
注意可以使用chkconfig --help
查看chkconfig 的命令。
- 如果需要删除该服务,使用
chkconfig --del
{服务名称} - 如果更改服务脚本,重新添加,可以使用
chkconfig --override
{服务名称}
5、之后使用如下命令启动tomcat。
#service tomcat start
6、具体的shell脚本可以参考Catalina.sh,有的博客是将该脚本复制之后添加一些信息,然后添加至服务的。可以参考参考网址
(侵权即删)