ICode9

精准搜索请尝试: 精确搜索
首页 > 编程语言> 文章详细

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

2019-07-01 15:53:33  阅读:191  来源: 互联网

标签:c windows-services topshelf


我正在使用Topshelf来创建Windows服务.此服务将尝试恢复前3个故障,但在此之后,它将不再起作用.

检查主机上的服务中的服务显示:

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

服务恢复代码如下所示:

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

检查事件日志会在恢复失败后显示以下消息:

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

从上面可以明显看出.第四次不会触发恢复.

这是Windows错误,Topshelf问题,还是我的配置有问题?

解决方法:

您必须为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); 
                });

看看sample

标签:c,windows-services,topshelf
来源: https://codeday.me/bug/20190701/1348385.html

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有