From 3c6d8e27655de82e6ca683a4110bb0c0a07f4c75 Mon Sep 17 00:00:00 2001 From: Oleg Nenashev Date: Wed, 14 Dec 2016 18:16:56 +0100 Subject: [PATCH] Issue #146 - Improve logging of the Uninstall Operation. This change does not change the behavior (return code, etc.) of the WinSW logic, but on the other hand it provides diagnostic information. --- src/Core/ServiceWrapper/Main.cs | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/src/Core/ServiceWrapper/Main.cs b/src/Core/ServiceWrapper/Main.cs index e09be8e..c11a99b 100644 --- a/src/Core/ServiceWrapper/Main.cs +++ b/src/Core/ServiceWrapper/Main.cs @@ -644,11 +644,19 @@ namespace winsw } if (args[0] == "uninstall") { + Log.Info("Uninstalling the service with id '" + d.Id + "'"); if (s == null) { - Console.WriteLine("Warning! The service with id '" + d.Id + "' does not exist. Nothing to uninstall"); + Log.Warn("The service with id '" + d.Id + "' does not exist. Nothing to uninstall"); return; // there's no such service, so consider it already uninstalled } + if (s.Started) + { + // We could fail the opeartion here, but it would be an incompatible change. + // So it is just a warning + Log.Warn("The service with id '" + d.Id + "' is running. It may be impossible to uninstall it"); + } + try { s.Delete(); @@ -656,7 +664,17 @@ namespace winsw catch (WmiException e) { if (e.ErrorCode == ReturnValue.ServiceMarkedForDeletion) + { + Log.Error("Failed to uninstall the service with id '" + d.Id + "'" + + ". It has been marked for deletion."); + + // TODO: change the default behavior to Error? return; // it's already uninstalled, so consider it a success + } + else + { + Log.Fatal("Failed to uninstall the service with id '" + d.Id + "'. WMI Error code is '" + e.ErrorCode + "'"); + } throw e; } return;