Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do you get the current failure count for a windows service

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).

like image 716
Draemon Avatar asked Dec 07 '09 18:12

Draemon


People also ask

How do I reset the Count of failed services to 0?

The count is reset to 0 if the service has not failed for dwResetPeriod seconds. Calling ChangeServiceConfig2 with the dwResetPeriod of SERVICE_FAILURE_ACTIONS set to 0 will reset the count.

How does the service control manager Count the number of failures?

The service control manager counts the number of times each service has failed since the system booted. The count is reset to 0 if the service has not failed for dwResetPeriod seconds.

How do I reset the number of failures in service_failure_actions?

Calling ChangeServiceConfig2 with the dwResetPeriod of SERVICE_FAILURE_ACTIONS set to 0 will reset the count. You will need to query (see QueryServiceConfig2) the original setting of dwResetPeriod, set it to zero then reset it back to the original to preserve the state.

What is reset fail count after setting in Salesforce?

Reset fail count after setting is amount of time from service start after which fail counter will be reseted. According to defined sample configurations where each service close unexpectedly after 5s from start each case never hits reset counter definition. To reset counter timeout should be less then 5s ex.


1 Answers

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.

like image 184
Remy Lebeau Avatar answered Jan 02 '23 11:01

Remy Lebeau