

But every now and then, the batch file continues running in some form or fashion — getting hung, I suppose — and of course AlwaysUp is satisfied and doesn’t restart it. I know I can have AlwaysUp restart it every day at a certain time, but I need the copying process to run very regularly. How do I make that happen?
— Rowan
Hi Rowan. That’s an interesting scenario. A couple of solutions jump to mind…
Solution #1: Stop/restart your batch file hourly
You mentioned that AlwaysUp can restart your batch file daily, but did you know that it can do so hourly as well?
Edit your application in AlwaysUp and you’ll find that capability on the Monitor tab:
That’s the easiest way to protect your batch file from a prolonged hang. With the hourly setting in place, your batch file will never get stuck for more than 60 minutes. Furthermore, you’ll be guaranteed a “fresh” run of your batch file at the top of every hour.
But what if you can’t wait for up to an hour? In that case, you’ll have to resort to the second solution. It involves a bit more work to set up, but in return it gives you much greater control.
Solution #2: Install a simple sanity check to stop/restart your batch file when it runs for too long
Are you familiar with the AlwaysUp sanity check feature? Basically, it’s a way to add sophisticated failure detection to the mix — and have AlwaysUp restart your application whenever something unusual happens. We’ll use a sanity check to restart your batch file if it runs for longer than you like.
To set that up:
Create a new sanity check batch file with a single line:
exit 1
Save it to your hard drive:
Start AlwaysUp.
Edit your batch file entry in AlwaysUp (by highlighting it and selecting Application > Edit/View from the menu).
Switch to the Monitor tab.
Check the Whenever it fails a periodic sanity check box and click the Set button:
In the Add Sanity Check window that comes up, select Check your application with a custom executable/script from the list:
Click Next to proceed.
On the following page, enter the full path to the sanity check batch file you created in step 1:
Click Next to move on.
How long are you willing to wait for your main batch file to do its work? That is, for how long should your batch file run before it’s declared as hung and needs to be terminated?
Whatever that duration is, enter it here. We’ve put in 2 minutes but you can go as low as 1 minute if you like:
Finally, review the summary and save your new sanity check:
And with that sanity check in place, here’s what will happen whenever AlwaysUp runs your batch file:
The batch file starts
If the batch file does its work and exits within 2 minutes, AlwaysUp will simply queue up the next run as you’ve specified on the Restart tab. All will be good.
If, however, the batch file hangs and remains running for longer than 2 minutes:
A second or two after to the 2-minute mark, AlwaysUp runs the sanity check batch file.
The sanity check batch file immediately exits with 1, which signals AlwaysUp to terminate the main batch file.
AlwaysUp kills the main batch file, thereby interrupting a potentially lengthy hang.
AlwaysUp queues up the next run as you’ve specified on the Restart tab.
The end result is that your batch file will never run for more than a few seconds longer that two minutes — or whatever threshold you set for your situation.
Thanks again for reaching out, Rowan. Please try one (or both) of these solutions and let us know how you get on!