views:

253

answers:

2

I have a service which will fail when certain resources are unavailable. I have configured it to try restarting twice, then send me an SMS on the third attempt. Unfortunately windows only gives you the option to reset the failure count after a certain number of days, whereas I really want it to reset on every third failure. The problem is that once the service is running again, one more failure will cause it to send another SMS and not even try to restart the service.

So I want to include in my SMS script some code to reset the failure counter. I have found the following registry location:

HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\

Which contains among other things (binary) settings for failure actions, but no counter as far as I can tell.

The sc command lets you query all sorts of stuff, but also doesn't return a failure count.

Ideally I'd like a way to query/reset the failure counter programatically, but a commandline or registry solution would be fine (since I can script them).

A: 

The Win32 API allows you to specify the failure count be reset after X number of seconds, not X number of days. Look at the dwResetPeriod members of the SERVICE_FAILURE_ACTIONS structure.

A for the failure counter itself, that is maintained privately inside of the SCM, which knows how many times a given service has failed since Windows was booted. That counter is not accessible for applications to reset manually, or even to query.

Remy Lebeau - TeamB
What a shocking inadequacy! It means that behaviour such as "SMS every third failure" isn't possible. Through the API, I could set the reset time so that it coincided with a wait-restart-wait-restart-sms cycle, but A) that assumes predictable failure timing, and B) I don't like configuring a service through the API when the UI can't handle those settings.
Draemon
A: 

Hi! I am a developer for an open source windows service hosting framework called Daemoniq. Setting service recovery options is one of its features. You can download it from http://daemoniq.org

Current features include:

  • container agnostic service location via the CommonServiceLocator
  • set common service properties like serviceName, displayName, description and serviceStartMode via app.config
  • run multiple windows services on the same process
  • set recovery options via app.config
  • set services depended on via app.config
  • set service process credentials via command-line
  • install, uninstall, debug services via command-line

Thanks!

jake.stateresa