TOMCAT添加系统服务

2015-12-3116:02:55TOMCAT添加系统服务已关闭评论 616

#!/bin/bash
#chkconfig: 345 96 21
#description: tomcat server
#JDK安装路径

JAVA_HOME="/usr/java/jdk1.7.0_51"

#tomcat安装路径
CATALINA_HOME="/usr/local/tomcat"

#获取tomcat服务的进程号PID
PID=ps -ef |grep /usr/local/tomcat |grep java |grep -v grep |awk '{print $2}'
# Source function library.
. /etc/rc.d/init.d/functions
# Source networking configuration.
. /etc/sysconfig/network
prog=tomcat
start() {
[ "$NETWORKING" = "no" ] && exit 0
echo -n $"Starting $prog: "
$CATALINA_HOME/bin/startup.sh 2>/dev/null 1>&2 && success || failure
echo
return $RETVAL
}

stop() {
echo -n $"Shutting $prog: "
$CATALINA_HOME/bin/shutdown.sh 2>/dev/null 1>&2 && success || failure
echo
return $RETVAL
}

case "$1" in
start)
start
;;
stop)
stop
;;
status)
[ -n "$PID" ] && echo "[${PID}]tomcat is running..."
[ ! -n "$PID" ] && echo "tomcat is stopped"
;;
restart)
stop
start
;;
reload)
exit 3
;;
*)
echo $"Usage: $0 {start|stop|status|restart}"
exit 2
esac