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