1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 | #!/bin/bash #chkconfig 2345 10 90 # description: start and stop tomcat service scripts # author : zhangxiaolong # email : bawoshiji004@163.com # 添加CATALINA_HOME变量和JDK变量,更换项目只需要更换此变量即可,如果今后一个应用一台服务器,可以使用一样的名字来操作 CATALINA_HOME=/opt/tomcat # 由于catalina.sh使用了许多系统自定义变量,并且程序开发过程中也有可能反复调用系统变量,因此,在此处需要source系统的环境配置,以免程序在调用系统默认变量的时候出问题 source /etc/profile # 方便jenkins通过ssh部署,需要修改sudoers配置其不必打开一个tty去操作,如果用不到,可以将其注释/删除掉 PRO=`cat /etc/sudoers | grep "Defaults requiretty" | md5sum | awk '{print $1}'` PRO_DEF=`echo "# Defaults requiretty" | md5sum | awk '{print $1}'` [ ${PRO} != ${PRO_DEF} ] && sed -i 's\Defaults requiretty\# Defaults requiretty\' /etc/sudoers # 注意,本脚本是根据catalina.pid进行操作的,如果没有,请在catalina.sh或者setenv.sh里的128行至130行左右(适用于tomcat7.0.65)加入以下内容: # [ -n "$CATALINA_HOME" ] && CATALINA_PID=$CATALINA_HOME/work/catalina.pid # 启动 start() { if [ -z `ps aux | grep $CATALINA_HOME | grep -v grep | awk '{print $2}'` ];then if [ -f $CATALINA_HOME/work/catalina.pid ]; then rm -rf $CATALINA_HOME/work/catalina.pid; fi source $CATALINA_HOME/bin/startup.sh else echo "$CATALINA_HOME service has start already!" fi } # 关闭 stop() { if [ -f $CATALINA_HOME/work/catalina.pid ]; then PID=`cat $CATALINA_HOME/work/catalina.pid`; rm -rf $CATALINA_HOME/work/catalina.pid; kill -9 $PID; echo "$CATALINA_HOME is stopped!" fi } # 查看状态 status() { if [ -z `ps aux | grep $CATALINA_HOME | grep -v grep | awk '{print $2}'` ];then if [ ! -f $CATALINA_HOME/work/catalina.pid ]; then echo "$CATALINA_HOME is not running!" else echo "$CATALINA_HOME is not running ,but pid file find!"; echo "system will removed the pid file"; rm -rf $CATALINA_HOME/work/catalina.pid; fi else PID=`cat $CATALINA_HOME/work/catalina.pid` echo "$CATALINA_HOME is running, pid is $PID!" fi } case "$1" in start) start;; stop) stop;; status) status;; restart) stop; sleep 1; start;; *) echo $"USEAGE: $0 {start|stop|status|restart}";; esac |
本文出自 “” 博客,请务必保留此出处