tomcat添加为linux服务

来源:互联网 发布:快递员扫码发短信软件 编辑:程序博客网 时间:2024/05/30 02:24

linux服务器上每次都要跑到tomcat目录中bin启动服务,比较麻烦,可以将tomcat的启动添加至linux的service中。以下是个简单的示例,具体的shell脚本需要自己去完善。

1、编辑shell脚本。命名为tomcat.sh(你自己想叫啥就叫啥)。

#!/bin/bash# chkconfig: 2345 10 90#description: start and stop tomcat by serviceexport TOMCAT_HOME=/java/tomcat/#startstart(){echo -n "The fucking tomcat is starting...wait for a few minutes"./$TOMCAT_HOME/bin.start.shecho}#stopstop(){echo -n "The mother fucker tomcat is shutting down "./$TOMCAT_HOME/bin/shutdown.shecho}#restartrestart(){stopsleep 2startecho }case "$1" instart)start ;;stop)stop ;;restart)restart ;;*)echo "use tomcat {start|stop|restart}"exit 1esacexit 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,有的博客是将该脚本复制之后添加一些信息,然后添加至服务的。可以参考参考网址
(侵权即删)