fX\#}4yb[*OrU0首先是在root用户的crontab中添加如下一行:
xjL'[1X$NbbH0*/5 * * * * /xxx/xxx/monitorM2U.sh
Fc{^ k;pP%|0&peSo9o(R,n] T0~0即每5分钟执行一下脚本/xxx/xxx/monitorM2U.sh,这个脚本的内容是:51Testing软件测试网*P$f v5CX:{)n5c
8E
s9I7cW[0cd /xxx/xxx/xxx/classes;
MA.cS{02f.A5slxZQm9]^0nohup “${JAVA_HOME}”/bin/java –cp ".:${CLASSPATH} " com.mdcchina.m2u.monitor.ResponseMonitor &
Z"F8H.Pc051Testing软件测试网EPj.g$t yv其中com.mdcchina.m2u.monitor.ResponseMonitor的代码是:
Lp3I~D051Testing软件测试网m|Lj3f{]/*
'M\6Q5Os$U Ag O\051Testing软件测试网3K&@W|V*sSP4xGa5q * Created on 2005-9-851Testing软件测试网J]8XYx
dw
51Testing软件测试网8}9PyjB&] *51Testing软件测试网wY5qI},^&T9z)SP1la
"sGBx C_\5}G-fl0 */
J7hD \m0m.H ]0@L8d~
W~Or`p0package com.mdcchina.m2u.monitor;51Testing软件测试网X&G#JCpARI
+\ TP JT7Bje&}/GE0import java.io.IOException;51Testing软件测试网(lq%nyD7y
z^-I3{/rR8c0import java.util.Date;51Testing软件测试网)c2f!dw7FD%r4YZ
1j
n)AIB!i0import org.apache.commons.httpclient.HttpClient;
b2H,zHxTd0K#`$y7NIJx0import org.apache.commons.httpclient.methods.GetMethod;51Testing软件测试网+^#zV`JD
D
51Testing软件测试网/w@3q
V%w
a/**51Testing软件测试网Yl*b;KW JI \]
AG;_*pe0 * @author Hao Wei 监控m2u进程是否能够访问,如果不能就重启之51Testing软件测试网?wMVG~5i}
i1q
!W*t's)WG%V0 */
3]6DEn1D7Pz+}0;MeIh#Q)@,J9H^ U0public class ResponseMonitor {
-`U Pt&\@7\&I`c02Bl1}
I#H4N0 public static void main(String[] args) {51Testing软件测试网sE q9FkK0`-do!V'x
9R,s4I Tx+B
} C0|!vG0 if (!new ResponseMonitor()51Testing软件测试网h8foX)e|,Dh#G
d8l^e)m0 . canRequest ("http://www.m2u.cn/albumshare/benber")) { //用来监控的地址
!m3`7F$L({Jj d051Testing软件测试网5K{IK#^ log("FATAL ERROR!!!!!!!!!!!!!\nM2U cannot be visit, it will be restarted!");
^0l(J a8{;pjxz051Testing软件测试网d"S\|,B,AVZ,Kio/**
5g3SLG
l B051Testing软件测试网U(?n~Ay4w~* 在此可加入发送短信报警或记录失败日志的代码
r'tJ&d#l0