Merge pull request #341 from new-mikha/master

Add stopwait command - same as stop, but waits until the service is actually stopped:
pull/513/head v2.9.0
Oleg Nenashev 2020-05-10 23:18:45 +02:00 committed by GitHub
commit ee29eee8cf
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 25 additions and 0 deletions

View File

@ -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.

View File

@ -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