Recipe7.6.Performing an Action Automatically When a Service Fails


Recipe 7.6. Performing an Action Automatically When a Service Fails

Problem

You want to perform an action automatically when a service fails.

Solution

Using a graphical user interface

  1. Open the Services snap-in.

  2. In the left pane, double-click on the service you want to configure.

  3. Click the Recovery tab.

  4. Configure the failure options you want and click OK.

Using a command-line interface:

The following command causes the MyMonitor service to automatically restart after two failures and reboot on the third. Each failure can be up to five seconds apart.

> sc failure MyMonitor reset= 3600 reboot="Restarting due to repeated MyMonitor failure" actions= restart/5000/restart/5000/reboot/5000

Using VBScript

The Win32_Service class does not support setting the recovery options of a service.

Discussion

Windows 2000 added a new capability that was sorely missing in previous versions of Windows: the ability to automatically perform a specified action when a service fails. You can configure an action to occur after the first, second, and subsequent failures. The actions you can take include no action (the default), restarting the service, running a program, or restarting the computer. Restarting the service or computer should be used as a last resort because they could mask underlying problems.

You can also reset the failure count after a certain number of days. So let's say that you have a service that regularly fails multiple times a day, but you only want it to restart itself after the first failure every day. You would configure the first failure action to restart the service and set the reset fail count to 1 day.

You can even combine multiple actions by choosing to run a program after service failure. You can create a simple batch file that restarts the service and emails you a report. This gives you a lot of flexibility in how you handle service failures.



Windows Server Cookbook
Windows Server Cookbook for Windows Server 2003 and Windows 2000
ISBN: 0596006330
EAN: 2147483647
Year: 2006
Pages: 380
Authors: Robbie Allen

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net