Topshelf halts service recovery after third attempt
Asked Answered
L

1

6

I am using Topshelf to create a Windows Service. This service will attempt recovery the first 3 failures, but after that, it no longer work.

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?

Leninakan answered 20/11, 2017 at 12:51 Comment(0)
O
4

You must set bottom config for topshelf recovery setting:

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

Organist answered 24/1, 2019 at 10:51 Comment(2)
If I change the code "rc.RestartService(delayInMinutes: 5);" to "rc.RestartService(delayInMinutes: 3);" will only the delay time be afected or will Topshelf adopt another logic?Strohben
What is the important/significant difference between the code in your answer and the code in the OP?Cochabamba

© 2022 - 2024 — McMap. All rights reserved.