From 0ee22abe8ca90707e40572faf7bca6c1139f9de2 Mon Sep 17 00:00:00 2001 From: Kohsuke Kawaguchi Date: Wed, 8 Jan 2014 21:34:12 -0800 Subject: [PATCH] Propagate abnormal termination to Windows SCM. This will enable it to restart the service based on policies. --- Main.cs | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/Main.cs b/Main.cs index f2d894a..a6c3f7e 100644 --- a/Main.cs +++ b/Main.cs @@ -280,6 +280,9 @@ namespace winsw } } + /// + /// Called when we are told by Windows SCM to exit. + /// private void StopIt() { string stoparguments = descriptor.Stoparguments; @@ -432,7 +435,12 @@ namespace winsw } else { - LogEvent("Child process [" + msg + "] terminated with " + process.ExitCode, EventLogEntryType.Warning); + LogEvent("Child process [" + msg + "] finished with " + process.ExitCode, EventLogEntryType.Warning); + // if we finished orderly, report that to SCM. + // by not reporting unclean shutdown, we let Windows SCM to decide if it wants to + // restart the service automatically + if (process.ExitCode == 0) + SignalShutdownComplete(); Environment.Exit(process.ExitCode); } }