• 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

  • 相关阅读:
    微信企业号开发:UserAgent
    用sinopia搭建内部npm服务
    python format用法详解
    python正则表达式re之compile函数解析
    Socket通信原理
    TCP半开连接与半闭连接
    使用npm安装一些包失败了的看过来(npm国内镜像介绍)
    UI优秀框架(库)
    关于 WebView 知识点的详解
    CommonJS规范
  • 原文地址:https://www.cnblogs.com/chucklu/p/15527441.html
Copyright © 2020-2023  润新知