我在 Tomcat 服务器上运行 Web 应用程序。服务器代码中存在一个难以检测的问题,导致它每天崩溃一次或两次。当我有时间时,我会深入纠正它。但是直到那一天,在有问题的情况下重新启动tomcat(/etc/init.d/tomcat7 restart)或基本上重新启动机器现在似乎也是不错的解决方案。我想用 wget 而不是 grep 或其他东西来检测服务器的活跃度,因为即使 tomcat 正在运行我的服务也可能已关闭。
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.
或者说完就卡住了
--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。