您的位置:寻梦网首页编程乐园Java天地JSP 专辑JSP001 HTML 离线版
Java 天地
JSP001 HTML 离线版
论坛精华 >> Tomcat >> UNIX 下 TOMCAT 守护进程

由 webmaster 发布于: 2001-02-02 15:29

Talking

鉴于 TOMCAT 经常出现不稳定的现象,我们必须对 TOMCAT 进行监控。
monitor-tomcat.sh 作用是每秒检查一次
TOMCAT 进程,如果发现 TOMCAT 进程有问题则立刻重新启动 TOMCAT 。

monitor-tomcat.sh
=================================================
#!/bin/sh

count=1
while [ 1 -eq 1 ]
do
if [ `ps -ef | grep java | grep -v grep | wc -l` -lt 1 ]
then
cd /www/tomcat/bin
echo "Down at:" >> /www/logs/tomcat/monitor-info.log
date >> /www/logs/tomcat/monitor-info.log
nohup ./startup.sh &
fi
sleep 1
count=$count+1

#if [ count -eq 900 ]
#then
# jpid=`ps -ef | grep java | grep -v grep | cut -c0-5`
# kill -9 $jpid
# count=1
#fi
done

vi /www/tomcat/bin/delnohup
=================================================
(create delnohup script)=>
cd /usr/local/tomcat/bin
rm nohup.out
touch nohup.out


vi /www/tomcat/bin/killjava
=================================================
(create killjava script)=>
/usr/bin/pkill -9 java


vi /var/spool/cron/crontabs/root
=================================================
(add in the end )=>
#30 * * * * /www/tomcat/bin/killjava
#delete nohup.out
0,10,20,30,40,50 * * * * /www/tomcat/bin/delnohup


How to start
=================================================
(Activation /var/spool/cron/crontabs/root script)=>
cd /etc/rc2.d
./S75cron stop
./S75cron start;

chmod 755 delnohup
chmod 755 monitor-tomcat.sh
nohup ./monitor-tomcat.sh &

Macro Zeng



资料来源: JSP001.com