我正在Tomcat服务器上运行Web应用程序。服务器代码中存在一个难以检测到的问题,导致它每天崩溃一次或两次。有空的时候,我会深入地纠正它。但直到那一天,在重新启动tomcat(/etc/init.d/tomcat7 restart)的问题情况下,或者基本上重新启动计算机,现在看来还是相当不错的解决方案。我想用wget而不是grep或其他东西来检测服务器的活力,因为即使tomcat正在运行我的服务可能会失败。如果Web服务(tomcat7)没有响应,重新启动
wget localhost:8080/MyService/
输出
--2012-12-04 14:10:20-- http://localhost:8080/MyService/
Resolving localhost... 127.0.0.1
Connecting to localhost|127.0.0.1|:8080... connected.
HTTP request sent, awaiting response... 200 OK
Length: 2777 (2.7K) [text/html]
Saving to: “index.html.3”
100%[======================================>] 2,777 --.-K/s in 0s
2012-12-04 14:10:20 (223 MB/s) - “index.html.3” saved [2777/2777]
时,我的服务了。并输出
Resolving localhost... 127.0.0.1
Connecting to localhost|127.0.0.1|:8080... failed: Connection refused.
或只是stucks说
--2012-12-04 14:07:34-- http://localhost:8080/MyService/
Resolving localhost... 127.0.0.1
Connecting to localhost|127.0.0.1|:8080... connected.
HTTP request sent, awaiting response...
否则后。你能否给我提供一个cron作业的shell脚本或其他的东西来做到这一点。如果有替代方案,我宁愿不使用cron。