{"id":3452,"date":"2017-11-06T16:39:19","date_gmt":"2017-11-07T00:39:19","guid":{"rendered":"https:\/\/www.coretechnologies.com\/blog\/?p=3452"},"modified":"2022-05-01T22:43:31","modified_gmt":"2022-05-02T05:43:31","slug":"restart-hung-script","status":"publish","type":"post","link":"https:\/\/www.coretechnologies.com\/blog\/alwaysup\/restart-hung-script\/","title":{"rendered":"Q &#038; A: How Do I get AlwaysUp to Restart my Hung Script?"},"content":{"rendered":"<div align=\"center\"><img loading=\"lazy\" decoding=\"async\" class=\"no-lazy-load\" src=\"\/blog\/images\/qa.webp\" title=\"Q &#038; A\" alt=\"Q &#038; A\" width=\"172\" height=\"127\" border=\"0\" \/><\/div>\n<div class=\"blog-qa-question-box\">\n<img loading=\"lazy\" decoding=\"async\" class=\"no-lazy-load\" src=\"https:\/\/cdn.coretechnologies.com\/images\/quotes-transparent-21x21.webp\" width=\"21\" height=\"21\" \/>&nbsp;&nbsp;My company uses <a href=\"\/products\/AlwaysUp\/AlwaysUpCLT\/\">AlwaysUp CLT<\/a> to run our script every 5 minutes as a windows service. The script starts running when the PC boots and repeats every 5 minutes throughout the day. It usually takes a few seconds to do its work on each run.<\/p>\n<p>\nHowever we have a nagging problem. After some hundred or more cycles, the script occasionally gets stuck and never finishes! When this happens, my customers get upset because their kiosks aren&#8217;t updated.\n<\/p>\n<p>\n<b>How can I get AlwaysUp to kill the script and restart it whenever it hangs?<\/b>\n<\/p>\n<p align=\"right\">&#8212; Dan @ <a href=\"http:\/\/laptopsanytime.com\/\" target=\"_blank\" rel=\"noopener noreferrer\">LaptopsAnytime<\/a><\/p>\n<\/div>\n<p>\nHi Dan. I&#8217;m not sure what your script does, but it is very unlikely that AlwaysUp will be able to tell that the script isn&#8217;t working properly. However we can use AlwaysUp&#8217;s powerful <a href=\"https:\/\/www.coretechnologies.com\/products\/AlwaysUp\/Plugins\/\">Sanity Check feature<\/a> to terminate (and restart) your script when it runs for too long.\n<\/p>\n<p>\nTo setup the sanity check with the AlwaysUp GUI (we&#8217;ll cover the CLT later):\n<\/p>\n<ol>\n<li>\n<p>\nCreate a new batch file with a single command: <b>exit 1<\/b><\/p>\n<div align=\"center\"><a href=\"\/blog\/images\/hung-sanity-check-batch-file.png\" class=\"zoomPopup\" rel=\"zoomgroup noopener noreferrer\" title=\"Create Sanity Check Batch File\" target=\"_blank\"><br \/>\n<img loading=\"lazy\" decoding=\"async\" src=\"\/blog\/images\/hung-sanity-check-batch-file.png\" width=\"398\" height=\"269\" title=\"Create Sanity Check Batch File (click to enlarge)\" alt=\"Create Sanity Check Batch File\" border=\"0\" ><\/a><\/div>\n<\/p>\n<p>\nSave the batch file to a convenient location on your file system. We have saved ours to &#8220;C:\\Scripts\\hung-sanity-check.bat&#8221;. Note the full path to the new file as we&#8217;ll need it in a later step.\n<\/p>\n<\/li>\n<li>\n<p>\nStart AlwaysUp. Highlight your application and select <b>Application &gt; Edit&#8230;<\/b> to summon the &#8220;Edit\/View Application&#8221; window.\n<\/p>\n<\/li>\n<li>\n<p>\nSwitch to the <b>Monitor<\/b> tab. Check the <b>Whenever it fails a sanity check<\/b> box and click the <b>&#8230;<\/b> button:<\/p>\n<div align=\"center\"><a href=\"\/blog\/images\/activate-sanity-check.png\" class=\"zoomPopup\" rel=\"zoomgroup noopener noreferrer\" title=\"Activate Sanity Check\" target=\"_blank\"><br \/>\n<img loading=\"lazy\" decoding=\"async\" src=\"\/blog\/images\/activate-sanity-check.png\" width=\"411\" height=\"592\" title=\"Activate Sanity Check (click to enlarge)\" alt=\"Activate Sanity Check\" border=\"0\" ><\/a><\/div>\n<\/p>\n<\/li>\n<li>\n<p>\nIn the &#8220;Configure Sanity Check&#8221; window that comes up:\n<\/p>\n<ol type=\"a\">\n<li>\n<p>In the <b>Run<\/b> section, enter the full path to the batch file you created in the first step.<\/p>\n<\/li>\n<li>\n<p>Using the <b>Every<\/b> controls, specify a time that you consider &#8220;too long&#8221; for your script to run. Since your script usually takes a few seconds to run, we recommend entering 2 minutes. That should give an unusually long run some extra time to complete, while ensuring that your customers never experience an outage lasting longer than a couple of minutes.<\/p>\n<\/li>\n<li>\n<p>Also, specify 2 minutes in the <b>Wait for<\/b> setting and check the <b>Also wait whenever the application is restarted<\/b> box. These ensure that your script will have time to complete before performing the first sanity check:<\/p>\n<div align=\"center\"><a href=\"\/blog\/images\/configure-hang-sanity-check.png\" class=\"zoomPopup\" rel=\"zoomgroup noopener noreferrer\" title=\"Configure Hang Sanity Check\" target=\"_blank\"><br \/>\n<img loading=\"lazy\" decoding=\"async\" src=\"\/blog\/images\/configure-hang-sanity-check.png\" width=\"439\" height=\"594\" title=\"Configure Hang Sanity Check (click to enlarge)\" alt=\"Configure Hang Sanity Check\" border=\"0\" ><\/a><\/div>\n<\/p>\n<\/li>\n<\/ol>\n<\/li>\n<li>\n<p>\nClick the <b>OK<\/b> button and save your settings in AlwaysUp.\n<\/p>\n<\/li>\n<\/ol>\n<p>\nWith the sanity check monitor in place, your script should never hang for longer than two minutes.\n<\/p>\n<h2><b>Command line switches for AlwaysUp CLT<\/b><\/h2>\n<p>\nTo achieve the setup described above with <a href=\"\/products\/AlwaysUp\/AlwaysUpCLT\/\">AlwaysUp CLT<\/a>, specify the following parameters to InstallService:<\/p>\n<ul>\n<li>\n<p>-t &#8220;&lt;Full path to your batch file&gt;&#8221;<\/p>\n<\/li>\n<li>\n<p>-a 120<\/p>\n<\/li>\n<li>\n<p>-xd 120<\/p>\n<\/li>\n<li>\n<p>-xr<\/p>\n<\/li>\n<\/ul>\n<p>\nFor example, our InstallService command line looked like this:<\/p>\n<blockquote><p>InstallService.exe &#8220;MyMainScript&#8221; &#8220;c:\\Scripts\\MyMainScript.bat&#8221; -k -m <b>-t &#8220;C:\\Scripts\\hung-sanity-check.bat&#8221; -a 120 -xd 2 -xr<\/b> -rn -f 3 0 -fd 5 1<\/p><\/blockquote>\n<p>\nFor a full description of these and other command line flags, please see the &#8220;Customized Sanity Checks&#8221; section (page 12) in the <a href=\"\/products\/AlwaysUp\/AlwaysUpCLT\/AlwaysUpCLTManual.pdf\" target=\"_blank\" rel=\"noopener noreferrer\">AlwaysUp CLT User Manual<\/a>.\n<\/p>\n<h2><b>Email alerts?<\/b><\/h2>\n<p>\nYou may also consider setting up email alerts &#8212; to inform you when your script had to be forcibly restarted. A timely notification may help you to diagnose and ultimately fix the underlying problem with your temperamental script. Until then, rest assured that AlwaysUp has you covered!<\/p>\n<!-- relpost-thumb-wrapper --><div class=\"relpost-thumb-wrapper\"><!-- filter-class --><div class=\"relpost-thumb-container\"><style>.relpost-block-single-image, .relpost-post-image { margin-bottom: 10px; }<\/style><h3>You may also like...<\/h3><div style=\"clear: both\"><\/div><div style=\"clear: both\"><\/div><!-- relpost-block-container --><div class=\"relpost-block-container relpost-block-column-layout\" style=\"--relposth-columns: 3;--relposth-columns_t: 2; --relposth-columns_m: 2\"><a href=\"https:\/\/www.coretechnologies.com\/blog\/alwaysup\/close-dialog-boxes-nircmd\/\"class=\"relpost-block-single\" ><div class=\"relpost-custom-block-single\"><img decoding=\"async\" loading=\"lazy\" class=\"relpost-block-single-image\" alt=\"Q&amp;A: Can AlwaysUp Close Dialog Boxes From My Application?\"  src=\"https:\/\/www.coretechnologies.com\/blog\/wp-content\/uploads\/dismiss-dialog-boxes-150x150-1.webp\" style=\"aspect-ratio:1\/1\" style=\"aspect-ratio:1\/1\"><\/img><div class=\"relpost-block-single-text\"  style=\"height: 75px;font-family: Arial;  font-size: 12px;  color: #333333;\"><h2 class=\"relpost_card_title\">Q&amp;A: Can AlwaysUp Close Dialog Boxes From My Application?<\/h2><\/div><\/div><\/a><a href=\"https:\/\/www.coretechnologies.com\/blog\/alwaysup\/restart-service-regularly\/\"class=\"relpost-block-single\" ><div class=\"relpost-custom-block-single\"><img decoding=\"async\" loading=\"lazy\" class=\"relpost-block-single-image\" alt=\"Q &amp; A: How do I Restart my Application\/Service Regularly from AlwaysUp?\"  src=\"https:\/\/www.coretechnologies.com\/blog\/wp-content\/uploads\/qa-150x150.png\" style=\"aspect-ratio:1\/1\" style=\"aspect-ratio:1\/1\"><\/img><div class=\"relpost-block-single-text\"  style=\"height: 75px;font-family: Arial;  font-size: 12px;  color: #333333;\"><h2 class=\"relpost_card_title\">Q &amp; A: How do I Restart my Application\/Service Regularly from AlwaysUp?<\/h2><\/div><\/div><\/a><a href=\"https:\/\/www.coretechnologies.com\/blog\/alwaysup\/version-12-5-released\/\"class=\"relpost-block-single\" ><div class=\"relpost-custom-block-single\"><img decoding=\"async\" loading=\"lazy\" class=\"relpost-block-single-image\" alt=\"AlwaysUp 12.5: Dropbox fixes, Email improvements, AutoStartDelay and More\"  src=\"https:\/\/www.coretechnologies.com\/blog\/wp-content\/uploads\/whats-new-2-150x150-1.png\" style=\"aspect-ratio:1\/1\" style=\"aspect-ratio:1\/1\"><\/img><div class=\"relpost-block-single-text\"  style=\"height: 75px;font-family: Arial;  font-size: 12px;  color: #333333;\"><h2 class=\"relpost_card_title\">AlwaysUp 12.5: Dropbox fixes, Email improvements, AutoStartDelay and More<\/h2><\/div><\/div><\/a><\/div><!-- close relpost-block-container --><div style=\"clear: both\"><\/div><\/div><!-- close filter class --><\/div><!-- close relpost-thumb-wrapper -->","protected":false},"excerpt":{"rendered":"<p>&nbsp;&nbsp;My company uses AlwaysUp CLT to run our script every 5 minutes as a windows service. The script starts running when the PC boots and repeats every 5 minutes throughout the day. It usually takes a few seconds to do &hellip; <a href=\"https:\/\/www.coretechnologies.com\/blog\/alwaysup\/restart-hung-script\/\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":3560,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[2],"tags":[26,127,138,142],"class_list":["post-3452","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-alwaysup","tag-alwaysup-tag","tag-qa","tag-sanity-check","tag-script"],"_links":{"self":[{"href":"https:\/\/www.coretechnologies.com\/blog\/wp-json\/wp\/v2\/posts\/3452","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.coretechnologies.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.coretechnologies.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.coretechnologies.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.coretechnologies.com\/blog\/wp-json\/wp\/v2\/comments?post=3452"}],"version-history":[{"count":3,"href":"https:\/\/www.coretechnologies.com\/blog\/wp-json\/wp\/v2\/posts\/3452\/revisions"}],"predecessor-version":[{"id":11299,"href":"https:\/\/www.coretechnologies.com\/blog\/wp-json\/wp\/v2\/posts\/3452\/revisions\/11299"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.coretechnologies.com\/blog\/wp-json\/wp\/v2\/media\/3560"}],"wp:attachment":[{"href":"https:\/\/www.coretechnologies.com\/blog\/wp-json\/wp\/v2\/media?parent=3452"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.coretechnologies.com\/blog\/wp-json\/wp\/v2\/categories?post=3452"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.coretechnologies.com\/blog\/wp-json\/wp\/v2\/tags?post=3452"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}