#!/bin/bash
### BEGIN INIT INFO
# Provides: le.com
# Required-Start: $service_fs $network
# Required-Stop: $service_fs
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: control service
# Description: control service tom
### END INIT INFO
PRO_HOME=/data/apache-tomcat-7.0.32/
start () {
PRO_PID=`ps -ef |grep "$PRO_HOME" |grep -v "grep" |awk '{print $2}'`
if [ -z $PRO_PID ];then
sh /data/apache-tomcat-7.0.32/bin/startup.sh &
else
echo "$0 is running"
fi
}
stop () {
PRO_PID=`ps -ef |grep "$PRO_HOME" |grep -v "grep" |awk '{print $2}'`
if [ -z $PRO_PID ];then
echo "$0 is not running"
else
echo "shutting down $0"
kill -9 "$PRO_PID" && echo "PID $PRO_PID killed."
fi
}
status () {
PRO_PID=`ps -ef |grep "$PRO_HOME" |grep -v "grep" |awk '{print $2}'`
if [ -z $PRO_PID ];then
echo "$0 is not running"
else
echo "$0 is running PID is $PRO_PID"
fi
}
case $1 in
start)
start
#tail -f $PRO_HOME/logs/
;;
stop)
stop
;;
status)
status
;;
restart)
stop
start
#tail -f $PRO_HOME/logs/
;;
*)
echo "Usage:$0 {start|stop|status|restart}."
;;
### BEGIN INIT INFO
# Provides: le.com
# Required-Start: $service_fs $network
# Required-Stop: $service_fs
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: control service
# Description: control service tom
### END INIT INFO
PRO_HOME=/data/apache-tomcat-7.0.32/
start () {
PRO_PID=`ps -ef |grep "$PRO_HOME" |grep -v "grep" |awk '{print $2}'`
if [ -z $PRO_PID ];then
sh /data/apache-tomcat-7.0.32/bin/startup.sh &
else
echo "$0 is running"
fi
}
stop () {
PRO_PID=`ps -ef |grep "$PRO_HOME" |grep -v "grep" |awk '{print $2}'`
if [ -z $PRO_PID ];then
echo "$0 is not running"
else
echo "shutting down $0"
kill -9 "$PRO_PID" && echo "PID $PRO_PID killed."
fi
}
status () {
PRO_PID=`ps -ef |grep "$PRO_HOME" |grep -v "grep" |awk '{print $2}'`
if [ -z $PRO_PID ];then
echo "$0 is not running"
else
echo "$0 is running PID is $PRO_PID"
fi
}
case $1 in
start)
start
#tail -f $PRO_HOME/logs/
;;
stop)
stop
;;
status)
status
;;
restart)
stop
start
#tail -f $PRO_HOME/logs/
;;
*)
echo "Usage:$0 {start|stop|status|restart}."
;;
esac
可以添加到开机启动
cd /etc/init.d
vi tomcat (写入以上脚本)
chmod 755 tomcat
chkconfig tomcat on