tomcat应用管理脚本

tomcat普通用户启动停止重启脚本(start|stop|status|restart)

运行命令:

xx.sh restart

#!/bin/bash
. /etc/init.d/functions
RETVAL=$?
export CATALINA_BASE=/cache1/tomcat-xxx-xxx
Tomcat=`basename $CATALINA_BASE`
[ -f $CATALINA_BASE/bin/startup.sh ] || exit 1
start(){
PIDS=`ps aux | grep java | grep $CATALINA_BASE | awk '{print $2}'`
if [ -n "$PIDS" ];then
echo -n "$Tomcat is running..."
echo_failure
echo
return 1
else
echo -n "Starting $Tomcat..."
JAVA_HOME=/usr/local/java su - tomcat $CATALINA_BASE/bin/startup.sh > /dev/null 2>&1
RETVAL=$?
[ $RETVAL -eq 0 ] && echo_success
[ $RETVAL -ne 0 ] && echo_failure
echo
return $RETVAL
fi
}
stop(){
echo -n "Shutting down $Tomcat..."
/bin/sh su - tomcat $CATALINA_BASE/bin/shutdown.sh > /dev/null 2>&1
sleep 3
PIDS=`ps aux | grep java | grep $CATALINA_BASE | awk '{print $2}'`
if [ -z "$PIDS" ];then
echo_success
echo
return 0
fi
echo -n "..."
sleep 5
PIDS=`ps aux | grep java | grep $CATALINA_BASE | awk '{print $2}'`
if [ -z "$PIDS" ];then
echo_success
echo

return 0
fi
echo -n "....."
sleep 8
PIDS=`ps aux | grep java | grep $CATALINA_BASE | awk '{print $2}'`
if [ -z "$PIDS" ];then
echo_success
echo
return 0
fi
echo -n "........"
kill -9 "$PIDS" >>/dev/null &
RETVAL=$?
[ $RETVAL -eq 0 ] && echo_success
[ $RETVAL -ne 0 ] && echo_failure
echo
sleep 1
return $RETVAL

}

case "$1" in
start)
start
;;
stop)
stop
;;
status)
PIDS=`ps aux | grep java | grep $CATALINA_BASE | awk '{print $2}'`
[ "$PIDS" != "" ] && echo -e "$Tomcat (pid $PIDS) is running"
[ "$PIDS" == "" ] && echo -e "$Tomcat is stop"
;;
restart)
stop
start
;;
*)
echo $"Usage: $0 {start|stop|status|restart}"
exit 1
;;
esac
exit $RETVA

weinxin
聂扬帆博客
一个分享IT运维相关工作经验和实战技巧的个人博客

发表评论

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: