Windows Services Recovery option doesn't work ... or I don't understand it RRS feed

Windows Services Recovery option doesn't work ... or I don't understand it

You could have a look at the blog post below, see if it helps you!

https://blogs.msdn.microsoft.com/jcalev/2008/01/10/some-tricks-with-service-restart-logic/

" First failure: what should occur the first time the service fails.  Valid options are "Take No Action", "Restart the Service", "Run a Program", and "Restart the Computer".


Second failure: same options the second time a service fails


Subsequent failures: same options for any subsequent failure


Reset fail count after: the number of days the service must be running before the failure count is reset


Restart service after: the amount of time in minutes to wait to restart the service


This is very nice, but it is very easy to misunderstand what these values actually do.  I have seen a number of services (and I tried this myself) set these values to 0 days and 0 minutes.  The problem is your service will continually restart if you set the failure count to reset after 0 days, if the service at least started correctly.  The result is only the first option ("first failure") will ever be run. 


To fix this, set the failure count to reset after one day.  The drawback to this approach is your service may stay stopped after failing several times but this likely means something is toast anyways.


One thing also to take into account is not all services will work with the reset logic - or in other words just setting the recovery options on any service does not guarantee that it will restart.  In order for the service to restart, it must exit abnormally.  This generally means the service must exist with a non-zero exit code and the service status must not be stopped (note: this has changed for Vista - it is possible to set the service status to stopped and provide an exit code to trigger the restart logic).

 

 

Best regards,
Leon

 

How can I automatically restart a Windows service 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:

SC failure w3svc reset= 432000  actions= restart/30000/restart/60000/run/60000
SC failure w3svc command= "MyBatchFile.cmd"

Your MyBatchFile.CMD file can look like this:

blat - -body "Service W3svc Failed" -subject "SERVICE ERROR" -to Notify@Example.com -server SMTP.Example.com -f Administrator@Example.com

 

What is Blat?
Blat is a Windows (32 & 64 bit) command line utility that sends eMail using SMTP or post to usenet using NNTP. 

 

 

Trying to set services to restart ANYTIME they fail. I need this setting to NEVER Expire?

回答1

The reset failure count is the "trigger" for the second recovery action. IF its is set to 0 it will never trigger the second condiction.

 

回答2

Setting "Reset fail count after" to 0 means "reset the fail count to 0 after each failure" until a reboot occurs.

The 0 effectively disables both, the "second failure" and "subsequent failure" actions and you will always get the "first failure" action, until you reboot the machine.

 

Clarification on Windows Service Recovery Actions Settings

问题

I am looking at the recovery actions settings and there are a couple of things that I need clarified.

If I have 0 days as my reset fail count after, and have the following as my actions:

  1. Restart the Service - on first failure
  2. Restart the Service - on second failure
  3. Reboot the Computer - on subsequent failures

Does the fail count get reset on a successful restart of the service?

Does the fail count get reset on the first failure? Hence never having a chance to perform the second or third actions?

On the third successive failure, the computer gets rebooted, the service get started and then fails again; would this reboot the computer again?

Thanks in advance!

Jaime

 

回答1

Setting "Reset fail count after:" to 0 means "reset the fail count to 0 after each failure".

This effectively disables both the "second failure" and "subsequent failure" actions and you will always get the "first failure" action.

 

回答2

I've tested that fail count on windows XPE. When the service run and I make it fail with "End Process" of the Windows task Manager. I have defined 3 recovery actions:

  1. restart service
  2. reboot
  3. run a program
  • On the first "end of process", the service is well restarted. OK.
  • On the second "end of process", the compuer is rebooted. OK.
  • After the reboot, if I end the process again, it is restarted and if I end it again, the computer is rebooted.

So it seems that this failure counter is reset after every reboot of the computer...

I precise that my fail count is configured to reset after 1 day.

 

 

 

 

 

 

RRS feed

作者:Chuck Lu    GitHub    
posted @   ChuckLu  阅读(308)  评论(0编辑  收藏  举报
编辑推荐:
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
· 浏览器原生「磁吸」效果!Anchor Positioning 锚点定位神器解析
· 没有源码,如何修改代码逻辑?
阅读排行:
· 全程不用写代码,我用AI程序员写了一个飞机大战
· DeepSeek 开源周回顾「GitHub 热点速览」
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· 记一次.NET内存居高不下排查解决与启示
· 白话解读 Dapr 1.15:你的「微服务管家」又秀新绝活了
历史上的今天:
2017-11-09 chrome的F12的inspect使用
2017-11-09 Macro expressions in kentico
2017-11-09 kentico version history and upgrade
2017-11-09 Compiler Warning (level 2) CS0436
2017-11-09 Creating new web parts kentico 10
2017-11-09 创建一个web user control
2017-11-09 kentico api
点击右上角即可分享
微信分享提示