{"id":2394,"date":"2022-08-30T15:24:30","date_gmt":"2022-08-30T15:24:30","guid":{"rendered":"https:\/\/unknownerror.org\/index.php\/2014\/01\/05\/reboot-if-tomcat7-service-is-not-responding-collection-of-common-programming-errors\/"},"modified":"2022-08-30T15:24:30","modified_gmt":"2022-08-30T15:24:30","slug":"reboot-if-tomcat7-service-is-not-responding-collection-of-common-programming-errors","status":"publish","type":"post","link":"https:\/\/unknownerror.org\/index.php\/2022\/08\/30\/reboot-if-tomcat7-service-is-not-responding-collection-of-common-programming-errors\/","title":{"rendered":"Reboot if tomcat7 service is not responding-Collection of common programming errors"},"content":{"rendered":"<p>I hope you have already found to root cause for your problem and been able to fix it properly. In case you or someone else would need a solution for this, here is a try for an answer.<\/p>\n<p>The thing here is that your service may sometimes &#8216;hang&#8217;, and the monitoring must also be able to catch it up. In the simple script below we place the wget status query to background, wait a few seconds and if it has not been able to retrieve status 200 from the service, restart it.<\/p>\n<pre><code>#!\/bin\/sh\n# WARNING, UNTESTED CODE !\n\nTMPFILE=`mktemp`\nWAITTIME=15\n\n# Run the test\nwget localhost:8080\/MyService\/ -o $TMPFILE &amp;\nWGETPID=$!\n\n# Wait few seconds and let the test finish\nsleep $WAITTIME\n\nif [ ! `grep \"HTTP request sent\" $TMPFILE |grep \"200 OK\"|wc -l` -gt 0 ]; then\n    echo \"The service did not return 200 in $WAITTIME seconds.\"\n    echo \"Restarting it.\"\n    \/etc\/init.d\/tomcat7 restart\nfi\n\n# Cleanup\nrm $TMPFILE\nkill $WGETPID\n<\/code><\/pre>\n<p>For scheduling, I really recommend cron for simplicity. Another choice would be to start this as a daemon, which would introduce unnecessary complexity, IMHO. Also some other (external) scheduler could be used, but I keep the cron simplest.<\/p>\n<p>Hopefully this helps.<\/p>\n<p id=\"rop\"><small>Originally posted 2014-01-05 22:45:02. <\/small><\/p>","protected":false},"excerpt":{"rendered":"<p>I hope you have already found to root cause for your problem and been able to fix it properly. In case you or someone else would need a solution for this, here is a try for an answer. The thing here is that your service may sometimes &#8216;hang&#8217;, and the monitoring must also be able [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-2394","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/2394","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/comments?post=2394"}],"version-history":[{"count":0,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/2394\/revisions"}],"wp:attachment":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/media?parent=2394"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/categories?post=2394"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/tags?post=2394"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}