I have a Windows service that exits unexpectedly every few days. Is there a simple way to monitor it to make sure it gets restarted quickly if it crashes?
I have a Windows service that exits unexpectedly every few days. Is there a simple way to monitor it to make sure it gets restarted quickly if it crashes?
Under the Services application, select the properties of the service in question.
View the recovery tab - there are all sorts of options - I'd set First & Second Failure to Restart the Service, Third to run a batch program that BLAT's out an email with the third failure notification.
You should also set the Reset Fail Count to 1 to reset the fail count daily.
EDIT:
Looks like you can do this via a command line:
Your MyBatchFile.CMD file can look like this:
Open Services.msc, double-click on the service to open the Properties of the service, there is a Recovery tab and those settings should allow you to restart the service upon failure.
Try to set recover time to zero:
The command line equivalent:
SC failure YOUR_SERVICE_NAME reset= 0 actions= restart/0/restart/0/restart/0
Anyway sometimes auto recover doesn't work correctly and it recommended to use third party software. It seems when service exit gracefully with exit code of 0 windows don't try to recover it.
I had similar requirement to start a service if stopped. The simplest solution I thought was to execute the below command in windows task scheduler every 5 minutes:
net start MyServiceName
This command will basically start the service (if stopped) and has no effect if the service is already running.
I am using ServiceKeeper on my windows 2008 server at HostForLife.eu and it works very good. Previously, I had a review on ServiceHawk, but I prefer to use ServiceKeeper for its easier management and interface.
I recently implemented a recovery option to run a powershell script that attempts to restart the service a defined number of times and sends an email notification at the conclusion, it also .
After several attempts (and despite all the other things I have seen) The configuration of fields on the recovery tab in services is as follows:
Program: Powershell.exe
**Not C:\Windows\System32\WindowsPowerShell\v1.0\Powershell.exe
Command line parameters: -command "& {SomePath\YourScript.ps1 '$args[0]' '$args[1]' '$args[n]'}"
eg: -command "& {C:\PowershellScripts\ServicesRecovery.ps1 'Service Name'}"
**The $args are parameters that will be passed to your script. These are not required.
here is the powershell script:
This was my answer on a similar thread Hope this helps...
You can schedule a simple vbs script like this one to restart periodically the service on the computer if needed.
Someone asked a similar question over at Super User: You could install a tool that monitors windows services. Something like Service Hawk would help you keep the services started, or allow you to schedule automatic restarts (possibly during the night) to keep the service running smoothly.