tomcat自启动脚本

1、 将该文件放在 /etc/init.d目录下,以后就可以使用service tomcat start/stop/status/restart等命令了

2、 在/etc/rc.d/rc3.d目录下,执行 ln –s /etc/init.d/tomcat /etc/rc.d/rc3.d/S99tomcat
这样,开机就会自动启动Tomcat了。

3.如果不能运行,请检查
chmod 755 /etc/init.d/tomcat
chmod 755 apache-tomcat-5.5.25/
vi /etc/passwd
修改启动用户如
apache 的/sbin/nologin 为/bin/bash

4、 脚本
#!/bin/sh
#
# Start staff.macaufly.net webserver
# Currently installed under /home/jira and should moved to /home/tomcat later
#

TOMCAT_BIN=/home/tomcat6/bin
TOMCAT_USER=apache

start() {

stop
su - $TOMCAT_USER -c $TOMCAT_BIN/startup.sh
sleep 10
if netstat -an | grep 8080 >/dev/null
then
echo "Tomcat is running"
return 0
else
return 1
fi
}

stop() {
if netstat -an | grep 8080 | grep LISTEN >/dev/null
then
# try to shutdown the server first
echo "Now Shutdown the server..."
su - $TOMCAT_USER -c $TOMCAT_BIN/shutdown.sh
else
echo "Tomcat is not running"
return 0
fi

if netstat -an | grep 8080 | grep LISTEN
then
sleep 10
echo "Now kill it"
ps -ef | grep java | grep $TOMCAT_USER | awk '{print "kill -9 ", $2;}' | sh
fi

if netstat -an | grep 8080 | grep LISTEN >/dev/null
then
return 1 # still alive
else
echo "Tomcat is stopped"
return 0
fi
}

case "$1" in
start)
start
;;

stop)
stop
;;

restart)
start
;;

status)
if netstat -an |grep 8080|grep LISTEN >/dev/null
then
echo "Tomcat is Running"
else
echo "Tomcat is Not Running"
fi
;;

*)
echo $"Usage: $0 {start|stop|restart|status}"
exit 1
esac

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值