Skip to content

Commit

Permalink
Added ExitCode for unhandled exception so that service restarts
Browse files Browse the repository at this point in the history
  • Loading branch information
Chris Patterson committed Mar 23, 2013
1 parent 47fcda1 commit 32c92ae
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 4 deletions.
2 changes: 0 additions & 2 deletions src/SampleTopshelfService/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,6 @@ static int Main()
r.RestartService(0);
r.RestartService(0);
r.RestartService(0);

r.OnCrashOnly();
});

x.AddCommandLineSwitch("throwonstart", v => throwOnStart = v);
Expand Down
7 changes: 5 additions & 2 deletions src/Topshelf/Runtime/Windows/WindowsServiceHost.cs
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,8 @@ protected override void OnShutdown()
}
catch (Exception ex)
{
_log.Fatal("The service did not shut down gracefully", ex);
_log.Fatal("The service did not shut down gracefully", ex);
ExitCode = (int)TopshelfExitCode.StopServiceFailed;
throw;
}
}
Expand All @@ -220,7 +221,9 @@ protected override void Dispose(bool disposing)

void CatchUnhandledException(object sender, UnhandledExceptionEventArgs e)
{
_log.Error("The service threw an unhandled exception", (Exception)e.ExceptionObject);
_log.Error("The service threw an unhandled exception", (Exception)e.ExceptionObject);

ExitCode = (int)TopshelfExitCode.UnhandledServiceException;

Stop();

Expand Down
1 change: 1 addition & 0 deletions src/Topshelf/TopshelfExitCode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,6 @@ public enum TopshelfExitCode
StartServiceFailed = 5,
StopServiceFailed = 6,
ServiceAlreadyRunning = 7,
UnhandledServiceException = 8,
}
}

0 comments on commit 32c92ae

Please sign in to comment.