Linux下tomcat自起服务

接上篇文章Linux下安装tomcat详细步骤https://blog.csdn.net/swiftly_654123/article/details/81952550


1、使用root用户进入etc/init.d

cd etc/init.d

2、使用vi 编辑tomcat服务

vi tomcat

3、在vi 编辑器中加入以下脚本命令

#! /bin/sh
#
# tomcatd  This shell script takes care of starting and stopping tomcat
#
# chkconfig: 2345 59 63

# Source funcation library.
. /etc/init.d/functions

# Source networking configuration.
. /etc/sysconfig/network
export JAVA_HOME=/usr/local/java/jdk1.7.0_80
export tomcat_home=/usr/local/tomcat7
export tomcatStart=$tomcat_home/bin/startup.sh
export tomcatStop=$tomcat_home/bin/shutdown.sh

start() {
    $tomcatStart
}

stop() {
    $tomcatStop
}

status() {
    num=`ps -ef | grep -w $tomcat_home | grep -v grep | wc -l`
    if [ $num -gt 0 ]
    then echo "tomcat is running"
    else echo "tomcat is stoped"
    fi
}

# See how we were called.

case "$1" in
start)
    start
    ;;
stop)
    stop
    ;;
restart)
    stop
    start
    ;;
status)
    status $prog
    ;;
*)
    echo $"Usage: $0 {start|stop|restart|status}"
    exit 2
esac
exit

4、添加脚本执行权限

chmod 755 /etc/init.d/tomcat

5、用chkconfig来添加到系统服务

chkconfig --add tomcat

6、用chkconfig查看是否添加成功

chkconfig --list tomcat

7、现在可以用service tomcat stop|start|status|restart 来管理tomcat了

service tomcat status

可以将tomcat进程关闭,重启Linux服务器,执行service tomcat status,会发现tomcat正在运行。

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值