However 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’t updated.
How can I get AlwaysUp to kill the script and restart it whenever it hangs?
— Dan @ LaptopsAnytime
Hi Dan. I’m not sure what your script does, but it is very unlikely that AlwaysUp will be able to tell that the script isn’t working properly. However we can use AlwaysUp’s powerful Sanity Check feature to terminate (and restart) your script when it runs for too long.
To setup the sanity check with the AlwaysUp GUI (we’ll cover the CLT later):
Create a new batch file with a single command: exit 1
Save the batch file to a convenient location on your file system. We have saved ours to “C:\Scripts\hung-sanity-check.bat”. Note the full path to the new file as we’ll need it in a later step.
Start AlwaysUp. Highlight your application and select Application > Edit… to summon the “Edit/View Application” window.
Switch to the Monitor tab. Check the Whenever it fails a sanity check box and click the … button:
In the “Configure Sanity Check” window that comes up:
In the Run section, enter the full path to the batch file you created in the first step.
Using the Every controls, specify a time that you consider “too long” 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.
Also, specify 2 minutes in the Wait for setting and check the Also wait whenever the application is restarted box. These ensure that your script will have time to complete before performing the first sanity check:
Click the OK button and save your settings in AlwaysUp.
With the sanity check monitor in place, your script should never hang for longer than two minutes.
Command line switches for AlwaysUp CLT
To achieve the setup described above with AlwaysUp CLT, specify the following parameters to InstallService:
-t “<Full path to your batch file>”
For example, our InstallService command line looked like this:
InstallService.exe “MyMainScript” “c:\Scripts\MyMainScript.bat” -k -m -t “C:\Scripts\hung-sanity-check.bat” -a 120 -xd 2 -xr -rn -f 3 0 -fd 5 1
For a full description of these and other command line flags, please see the “Customized Sanity Checks” section (page 12) in the AlwaysUp CLT User Manual.
You may also consider setting up email alerts — 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!