Topshelf 在第三次尝试后停止服务恢复
Topshelf halts service recovery after third attempt
我正在使用 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
我正在使用 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