From a8fee1975f0787aa44d9c42de3e4f8a4d44b6394 Mon Sep 17 00:00:00 2001 From: Michael Karmazin Date: Thu, 17 Oct 2019 11:21:08 +1100 Subject: [PATCH 1/2] Add stopwait command --- src/Core/ServiceWrapper/Main.cs | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/src/Core/ServiceWrapper/Main.cs b/src/Core/ServiceWrapper/Main.cs index 93345b0..0582d92 100644 --- a/src/Core/ServiceWrapper/Main.cs +++ b/src/Core/ServiceWrapper/Main.cs @@ -607,6 +607,10 @@ namespace winsw Stop(); return; + case "stopwait": + StopWait(); + return; + case "restart": Restart(); return; @@ -815,6 +819,25 @@ namespace winsw } } + void StopWait() + { + Log.Info("Stopping the service with id '" + descriptor.Id + "'"); + if (s is null) + ThrowNoSuchService(); + + if (s.Started) + s.StopService(); + + while (s != null && s.Started) + { + Log.Info("Waiting the service to stop..."); + Thread.Sleep(1000); + s = svc.Select(descriptor.Id); + } + + Log.Info("The service stopped."); + } + void Restart() { Log.Info("Restarting the service with id '" + descriptor.Id + "'"); @@ -984,6 +1007,7 @@ namespace winsw uninstall uninstall the service start start the service (must be installed before) stop stop the service + stopwait stop the service and wait until it's actually stopped restart restart the service restart! self-restart (can be called from child processes) status check the current status of the service From 621ad44ca174f74fe59145d2b4aa43117e42214a Mon Sep 17 00:00:00 2001 From: Michael Karmazin Date: Tue, 17 Dec 2019 08:50:15 +1100 Subject: [PATCH 2/2] Update README.md with 'stopwait' command description --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 943721f..29f28c0 100644 --- a/README.md +++ b/README.md @@ -31,6 +31,7 @@ Your renamed *WinSW.exe* binary also accepts the following commands: * `uninstall` to uninstall the service. The opposite operation of above. * `start` to start the service. The service must have already been installed. * `stop` to stop the service. +* `stopwait` to stop the service and wait until it's actually stopped. * `restart` to restart the service. If the service is not currently running, this command acts like `start`. * `status` to check the current status of the service. * This command prints one line to the console.