linux下tomcat自启动设置

时间:2022-06-14 15:37:50

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/lib/jvm/jre
export CATALINA_HOME=/usr/local/tomcat/apache-tomcat-7.0.64
export CATALINA_BASE=/usr/local/tomcat/apache-tomcat-7.0.64
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

查看,在服务列表里就会出现自定义的服务了。

chkconfig --list

5、开启tomcat系统服务

chkconfig tomcat on 

6 启动

tomcat:service tomcat start

7 停止

tomcat: service tomcat stop

  

其他:
java -version:查看JDK版本
linux:
whereis java
which java (java执行路径)
echo $JAVA_HOME
echo $PATH
参考
http://www.cnblogs.com/AloneSword/p/3417812.html

http://blog.csdn.net/jason5186/article/details/7317253