简体   繁体   English

Topshelf在第三次尝试后停止服务恢复

[英]Topshelf halts service recovery after third attempt

I am using Topshelf to create a Windows Service. 我正在使用Topshelf来创建Windows服务。 This service will attempt recovery the first 3 failures, but after that, it no longer work. 此服务将尝试恢复前3个故障,但在此之后,它将不再起作用。

Inspecting the service in Services on the host reveals: 检查主机上的服务中的服务显示:

First Failure:          Restart the Service
Second Failure:         Restart the Service
Subsequent Failures:    Restart the Service
Reset fail count after: 1 days
Restart service after:  2 minutes

The service recovery code looks like this: 服务恢复代码如下所示:

f.EnableServiceRecovery(r =>
{
    r.RestartService(2);
    r.RestartService(5);
    r.RestartService(5);
    r.OnCrashOnly();
    r.SetResetPeriod(1);
});

Inspecting the Event Log shows the following messages after failed recovery: 检查事件日志会在恢复失败后显示以下消息:

The MyService service terminated unexpectedly.  It has done this 1 time(s).  The following corrective action will be taken in 120000 milliseconds: Restart the service.
The MyService service terminated unexpectedly.  It has done this 2 time(s).  The following corrective action will be taken in 300000 milliseconds: Restart the service.
The MyService service terminated unexpectedly.  It has done this 3 time(s).  The following corrective action will be taken in 300000 milliseconds: Restart the service.
The MyService service terminated unexpectedly.  It has done this 4 time(s).

As is evident from the above. 从上面可以明显看出。 The fourth time does not trigger recovery. 第四次不会触发恢复。

Is this a Windows error, a Topshelf issue, or is there something wrong in my configuration? 这是Windows错误,Topshelf问题,还是我的配置有问题?

You must set bottom config for topshelf recovery setting: 您必须为topshelf恢复设置设置底部配置:

x.EnableServiceRecovery(rc =>
                {
                    // Has no corresponding setting in the Recovery dialogue.
                    // OnCrashOnly means the service will not restart if the application returns
                    // a non-zero exit code.  By convention, an exit code of zero means ‘success’.
                    rc.OnCrashOnly();
                    // Corresponds to ‘First failure: Restart the Service’
                    // Note: 0 minutes delay means restart immediately
                    rc.RestartService(delayInMinutes: 0); 
                    // Corresponds to ‘Second failure: Restart the Service’
                    // Note: TopShelf will configure a 1 minute delay before this restart, but the
                    // Recovery dialogue only shows the first restart delay (0 minutes)
                    rc.RestartService(delayInMinutes: 1); 
                    // Corresponds to ‘Subsequent failures: Restart the Service’
                    rc.RestartService(delayInMinutes: 5);
                    // Corresponds to ‘Reset fail count after: 1 days’
                    rc.SetResetPeriod(days: 1); 
                });

take a look in sample 看看样品

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM