Shell脚本放在上面,安装说明readme在脚本下面。
Shell脚本:
#!/bin/bash
#chkconfig: 2345 10 90
#description:Tomcat service
CATALINA_HOME=/usr/local/tomcat
TOMCAT_START=$CATALINA_HOME/bin/startup.sh
TOMCAT_STOP=$CATALINA_HOME/bin/shutdown.sh
export JAVA_HOME=/usr/java/latest
#process显示名称
PROGRESS=teaching
#pid存放文件
process_file=/tmp/${PROGRESS}_tomcat_process_id.txt
process_pid=/var/lock/subsys/${PROGRESS}
# source function library.
. /etc/rc.d/init.d/functions
# check that networking is up.
[ "${NETWORKING}" = "no" ] && exit 0
# check for tomcat script
if [ ! -f $CATALINA_HOME/bin/catalina.sh ]; then
echo "Tomcat not valilable..."
exit
fi
start(){
if [ -e ${process_pid} ];then
echo -n "${PROGRESS}: allready running"
echo
exit 1
fi
echo -n "Starting ${ROGRESS}: "
daemon $TOMCAT_START
echo
touch ${process_pid}
}
stop(){
ps x --width=1000 | grep "${CATALINA_HOME}" | grep -v "grep" | awk '{printf $1 " "}' > ${process_file}
read line < ${process_file}
if [ ! $line ]; then
if [ ! $1 ] ; then
echo "${PROGRESS} is stopped"
fi
else
if [ $line -gt 0 ]; then
echo ${PROGRESS} stopping
for pid in $line
do
kill ${pid}
done
sleep 3
echo ${PROGRESS} stopped
rm -f ${process_pid} echo
else
echo "${PROGRESS} is stopped"
fi
fi
}
restart(){
stop
start
}
status(){
ps x --width=1000 | grep "${CATALINA_HOME}" | grep -v "grep" | awk '{printf $1 " "}' > ${process_file}
read line < ${process_file}
if [ ! $line ]; then
echo "${PROGRESS} is stopped"
else
if [ $line -gt 0 ]; then
echo -n "${PROGRESS} ( pid " $line
echo -n ") is running..."
echo
else
echo "${PROGRESS} is stopped"
fi
fi
}
case "$1" in
start)
start ;;
stop)
stop ;;
restart)
stop 1
sleep 3
start ;;
status)
status ;;
*)
echo "Usage: ${PROGRESS} {start|stop|restart|status}"
exit 1
esac
exit 0
安装说明:
1.将tomcat文件改名为应用名称(比如改为teaching)
2. 打开tomcat文件,修改
#tomcat目录
CATALINA_HOME=/usr/local/tomcat
TOMCAT_START=$CATALINA_HOME/bin/startup.sh
TOMCAT_STOP=$CATALINA_HOME/bin/shutdown.sh
#java目录
export JAVA_HOME=/usr/java/latest
#process显示应用名称
PROGRESS=teaching
#pid存放文件
process_file=/tmp/${PROGRESS}_tomcat_process_id.txt
#pid文件
process_pid=/var/lock/subsys/${PROGRESS}
3.将teaching文件放入/etc/init.d/目录下
4. 执行:chmod 755 /etc/init.d/teaching
5. 加入service:chkconfig --add teaching
6. 执行如下命令查看是否安装成功:service teaching