linux tomcat自启动设置

Posted TonyLoveTT

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了linux tomcat自启动设置相关的知识,希望对你有一定的参考价值。

1、进入/etc/init.d

2、新建文件tomcat,内容如下:
#!/bin/sh
# chkconfig: 345 99 10
# description: Auto-starts tomcat
# /etc/init.d/tomcat
# Tomcat auto-start
# Source function library.
#. /etc/init.d/functions
# source networking configuration.
#. /etc/sysconfig/network
RETVAL=0
export JRE_HOME=/usr/jre1.6.0_22
export CATALINA_HOME=/usr/tomcat6
export CATALINA_BASE=/usr/tomcat6
start()
{
        if [ -f $CATALINA_HOME/bin/startup.sh ];
          then
            echo $"Starting Tomcat"
                $CATALINA_HOME/bin/startup.sh
            RETVAL=$?
            echo " OK"
            return $RETVAL
        fi
}
stop()
{
        if [ -f $CATALINA_HOME/bin/shutdown.sh ];
          then
            echo $"Stopping Tomcat"
                $CATALINA_HOME/bin/shutdown.sh
            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
exit $RETVAL

3、添加执行权限

sudo chmod +x /etc/init.d/tomcat
 
4、随系统启动
chkconfig --add tomcat

5、开启tomcat系统服务
chkconfig tomcat on

6、启动tomcat服务
serice tomcat start

以上是关于linux tomcat自启动设置的主要内容,如果未能解决你的问题,请参考以下文章

linux系统设置tomcat自启动

linux tomcat自启动设置

Linux:Tomcat配置及设置开机自启动

Linux设置tomcat开机自启动

Linux系统下设置Tomcat自启动

linux下设置tomcat自启动