码迷,mamicode.com
首页 > 系统相关 > 详细

Linux下设置Tomcat开机启动

时间:2017-07-29 12:59:22      阅读:240      评论:0      收藏:0      [点我收藏+]

标签:通过   命令   code   val   logs   ann   down   class   stop   

1.进入/etc/rc.d/init.d,新建文件tomcat,并让它成为可执行文件 chmod 755 tomcat.

[root@ecs-3c46 /]# cd /etc/rc.d/init.d
[root@ecs-3c46 init.d]# vi tomcat

#!/bin/bash
#
# /etc/rc.d/init.d/tomcat
# init script for tomcat precesses
#
# processname: tomcat
# description: tomcat is a j2se server
# chkconfig: 2345 86 16
# description: Start up the Tomcat servlet engine.

if [ -f /etc/init.d/functions ]; then
    . /etc/init.d/functions
elif [ -f /etc/rc.d/init.d/functions ]; then
    . /etc/rc.d/init.d/functions
else
    echo -e "/atomcat: unable to locate functions lib. Cannot continue."
exit -l
fi

RETVAL=$?
CATALINA_HOME="/usr/local/tomcat/apache-tomcat-8.0.44"

case "$1" in
    start)
        if [ -f $CATALINA_HOME/bin/startup.sh ]; then
            echo $"Starting Tomcat"
            $CATALINA_HOME/bin/startup.sh
        fi

    ;;
    stop)
        if [ -f $CATALINA_HOME/bin/shutdown.sh ]; then
            echo $"Stopping Tomcat"
            $CATALINA_HOME/bin/shutdown.sh
        fi
    ;;
    *)
        echo $"Usage: $0 {start|stop}"
        exit 1
    ;;
esac

exit $RETVAL


2.执行chkconfig --add tomcat

[root@ecs-3c46 ~]# chkconfig --add tomcat


3.这样就可以通过service tomcat start开启服务和service tomcat stop关闭服务

相关命令的意思如下:
-f filename  如果 filename为常规文件
$0 是脚本本身的名字
$? 是显示最后命令的退出状态,0表示没有错误,其他表示有错误

Linux下设置Tomcat开机启动

标签:通过   命令   code   val   logs   ann   down   class   stop   

原文地址:http://www.cnblogs.com/chenjianxiang/p/7255379.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!