Linux下设置Tomcat开机自启动

时间:2025-05-12 11:57:35
#!/bin/sh
# chkconfig: 345 99 10
# description: Auto-starts tomcat
# /etc//tomcat
# Tomcat auto-start
# Source function library.
#. /etc//functions
# source networking configuration.
#. /etc/sysconfig/network
RETVAL=0
export JRE_HOME=/usr/jdk1.8.0_131
export CATALINA_HOME=/usr/tomcat6
export CATALINA_BASE=/usr/tomcat6

start()
{
        if [ -f $CATALINA_HOME/bin/ ];
          then
            echo $"Starting Tomcat"
                $CATALINA_HOME/bin/
            RETVAL=$?
            echo " OK"
            return $RETVAL
        fi
}
stop()
{
        if [ -f $CATALINA_HOME/bin/ ];
          then
            echo $"Stopping Tomcat"
                $CATALINA_HOME/bin/
            RETVAL=$?
            sleep 1
            ps -fwwu tomcat | grep apache-tomcat|grep -v grep | grep -v PID | awk '{print $2}'|xargs kill -9
            echo " OK"
            # [ $RETVAL -eq 0 ] && rm -f /var/lock/...
            return $RETVAL
        fi
}

case "$1" in
 start)
        start
        ;;
 stop)  
        stop
        ;;
                                                
 restart)
         echo $"Restaring Tomcat"
         $0 stop
         sleep 1
         $0 start
         ;;
 *)
        echo $"Usage: $0 {start|stop|restart}"
        exit 1
        ;;
esac