tomcat 启动脚本一例

发布时间:2020-07-18编辑:脚本学堂
Tomcat 启动脚本一例,感兴趣的朋友可以参考下。

tomcat 启动脚本一例

复制代码 代码如下:

#!/bin/bash
# chkconfig: 2345 99 10
# description: Start or stop the Tomcat server

#pidfile: /var/run/tomcat.pid
. /etc/rc.d/init.d/functions
RETVAL=0
prog="Tomcat"
#设置环境变量
JAVA_HOME=/opt/j2sdk
CLASSPATH=/opt/j2sdk/lib/tools.jar
CATALINA_HOME=/opt/tomcat5
PID_FILE=/var/run/tomcat.pid
PATH=/usr/local/bin:/usr/bin:/bin:/usr/X11R6/bin:$JAVA_HOME/bin:$CATALINA_HOME/bin
export JAVA_HOME CLASSPATH CATALINA_HOME PATH
start(){
        echo -n "Starting $prog:"
        startup.sh   >/dev/null
        RETVAL=$?
        [ $RETVAL = 0 ] && touch /var/lock/subsys/tomcat
        [ $RETVAL = 0 ] && echo_success || echo_failure
        result=`ps -aux|grep  java|linuxjishu/13830.html target=_blank class=infotextkey>awk -F " " '{if ($11!~/grep/) print $2}'`
        if [ ! -z $PID_FILE ] ; then
        echo $result > $PID_FILE
        fi
        echo
        return $RETVAL

}
stop(){
        echo -n "Stopping $prog:"
        kill -9 `cat $PID_FILE`
        RETVAL=$?
        [ $RETVAL = 0 ] && rm /var/lock/subsys/tomcat
        [ $RETVAL = 0 ] && echo_success || echo_failure
        if [ ! -z $PID_FILE ] ; then
        rm -rf $PID_FILE
        fi
        echo
        return $RETVAL
}
status(){
        result=`ps -aux|grep  java|awk -F " " '{if ($11!~/grep/) print $2}'`
        if [ $result ] ; then
        echo "$prog (pid $result)  正在运行"
        else
        echo "$prog 已停"
        fi
}

case "$1" in
        start)
                start
                ;;
        stop)
                stop
                ;;
        status)
                status
                ;;
        restart|reload)
                stop
                start
                ;;
        *)
        echo "Usage:$0 {start|stop|status|restart|reload}"
        RETVAL=1
esac
exit $RETVAL