tomcat linux服务脚本

原创
2014/02/14 09:32
阅读数 126
#!/bin/bash  
#  
# Startup script for the tomcat  
#  
# chkconfig: 345 80 15  
# description: Tomcat is a Servlet+JSP Engine.  
  
# Source function library.  
. /etc/rc.d/init.d/functions  


basedir=/usr/local/tomcat

RETVAL=0  
  
start(){
        checkrun  
        if [ $RETVAL -eq 0 ]; then  
                echo "Starting tomcat"  
                $basedir/bin/startup.sh  
                touch /var/lock/subsys/tomcat  
        else  
                echo "tomcat allready running"  
        fi  
}  
  
stop(){
        checkrun  
        if [ $RETVAL -eq 1 ]; then  
                echo "Shutting down tomcat"  
                $basedir/bin/shutdown.sh  
                #while [ $RETVAL -eq 1 ]; do  
                        sleep 5  
                        #checkrun  
                #done  
                rm -f /var/lock/subsys/tomcat  
        else  
                echo "tomcat not running"  
        fi  
}  
  
checkrun(){  
        ps ax --width=1000 | grep "[o]rg.apache.catalina.startup.Bootstrap start" | awk '{printf $1 " "}' | wc | awk '{print $2}' >/tmp/tomcat_process_count.txt  
        read line < /tmp/tomcat_process_count.txt  
        if [ $line -gt 0 ]; then  
                RETVAL=1  
                return $RETVAL  
        else  
                RETVAL=0  
                return $RETVAL  
        fi  
}  
  
status(){  
        checkrun  
        if [ $RETVAL -eq 1 ]; then  
                echo -n "Tomcat ( pid "  
                ps ax --width=1000 | grep "org.apache.catalina.startup.Bootstrap start" | awk '{printf $1 " "}'  
                echo -n ") is running..."  
                echo  
        else  
                echo "Tomcat is stopped"  
        fi  
        echo "---------------------------------------------"  
}  
  
case "$1" in  
start)  
        start  
        ;;  
stop)  
        stop  
        ;;  
restart)  
        stop  
        start  
        ;;  
status)  
        status  
        $basedir/bin/catalina.sh version  
        ;;  
*)  
        echo "Usage: $0 {start|stop|restart|status}"  
        esac  
  
exit 0



展开阅读全文
打赏
0
4 收藏
分享
加载中
更多评论
打赏
0 评论
4 收藏
0
分享
返回顶部
顶部