Join 3,572 readers in helping fund MetaFilter (Hide)


How to Keep a Critical Program Running 24/7 in 3 Easy Steps
April 9, 2008 7:48 AM   Subscribe

I want to monitor a running program on an XP box to make sure it stays running. If the program should quit for whatever reason, I'd like a way to attempt to restart the program after xx - minutes/seconds, for xx - attempts.

Specifically, I want a Citrix/terminal application session to restart when I reboot the Citrix server without having to do it manually. This would preclude setting up an application to run as a service I presume.

The Citrix server needs bounced a couple times per week and the particular remote application session will be running a time and attendance program...so it needs to always be available.

This would also fix any intermittent network failures so I don't get called at 5:30 AM saying people have no way to punch the clock.

My Google-fu is failing me on this one.
posted by SparkyPine to Computers & Internet (5 answers total) 3 users marked this as a favorite
 
I'm not familiar with Citrix, but you could probably use Perl or another scripting language to keep the process alive. Cygwin includes a port of the ps utility, which you should be able to combine with regular expressions to make sure that the process is always running.
posted by sonic meat machine at 8:18 AM on April 9, 2008


No scripting language required! This is not a plate of beans, etc. What you are describing is functionality already built into Windows.

They are called Services. Services can be set to start up automatically when the system starts, and have configurable options for the first, second and third failures, including restarting the service, running another program, or restarting the whole computer.

There is also a configurable delay on how long to wait before restarting. Run "services.msc" and look at the Recovery tab of any random service to see what the options are.

Normally, to run as a service an executable needs to be written in a specific way, however Microsoft provide a utility called SRVANY that allows you to run any executable as a service. There are plenty of guides on the internet that will tell you how to set this up.

You'll need to get hold of the Windows Resource Kit, but that shouldn't be too hard.
posted by jon4009 at 8:41 AM on April 9, 2008


How about scheduling a batch file to run every few minutes?

Something like:

@echo off
tasklist > test.txt
FIND "notepad.exe" test.txt
if errorlevel 1 start notepad.exe

...where you replace notepad.exe with the executable filename of your application. Use the full path in the 'if errorlevel 1 start...' line.
posted by le morte de bea arthur at 8:42 AM on April 9, 2008


If you can't get SRVANY to work, there's a similar free program called ServiceEx which is probably worth a try. I use it with Hamachi and it works well for that.

Some apps may not be happy running as a service. If not, I found this shareware program which looks to do what you want. I don't have any experience with this program.
posted by kindall at 8:46 AM on April 9, 2008


All very good answers. I bookmarked this for future reference for other things, knowing how to convert a program into a service...very nice indeed!

Kindall FTW:

However, because of the quirky ways of Citrix (not wanting to run as a service), KeepAlive wins. I have tested it on my thin client and it restarts the application like a dancing minstrel. Will test a server reboot later tonight to finalize it all.

Thank you all for taking the time to help!
posted by SparkyPine at 1:20 PM on April 9, 2008


« Older Working in the US film industr...   |  I have been asked to put toget... Newer »
This thread is closed to new comments.