diff --git a/README.md b/README.md index de29c56..cd3558f 100644 --- a/README.md +++ b/README.md @@ -42,6 +42,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. diff --git a/src/Core/ServiceWrapper/Main.cs b/src/Core/ServiceWrapper/Main.cs index 98e0cdc..db51ea5 100644 --- a/src/Core/ServiceWrapper/Main.cs +++ b/src/Core/ServiceWrapper/Main.cs @@ -623,6 +623,10 @@ namespace winsw Stop(); return; + case "stopwait": + StopWait(); + return; + case "restart": Restart(); return; @@ -861,6 +865,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() { if (!elevated) @@ -1121,6 +1144,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