mirror of https://github.com/winsw/winsw
Add `dev kill` command
parent
788a0ff64b
commit
4414e36f6b
|
@ -285,6 +285,13 @@ namespace WinSW
|
|||
};
|
||||
|
||||
dev.Add(ps);
|
||||
|
||||
var kill = new Command("kill", "Terminates the service if it has stopped responding.")
|
||||
{
|
||||
Handler = CommandHandler.Create<string?, bool>(DevKill),
|
||||
};
|
||||
|
||||
dev.Add(kill);
|
||||
}
|
||||
|
||||
return new CommandLineBuilder(root)
|
||||
|
@ -909,6 +916,28 @@ namespace WinSW
|
|||
}
|
||||
}
|
||||
|
||||
void DevKill(string? pathToConfig, bool noElevate)
|
||||
{
|
||||
XmlServiceConfig config = CreateConfig(pathToConfig);
|
||||
|
||||
if (!elevated)
|
||||
{
|
||||
Elevate(noElevate);
|
||||
return;
|
||||
}
|
||||
|
||||
using ServiceManager scm = ServiceManager.Open();
|
||||
using Service sc = scm.OpenService(config.Name);
|
||||
|
||||
int processId = sc.ProcessId;
|
||||
if (processId >= 0)
|
||||
{
|
||||
using Process process = Process.GetProcessById(processId);
|
||||
|
||||
process.StopDescendants(config.StopTimeoutInMs);
|
||||
}
|
||||
}
|
||||
|
||||
static void Customize(string output, string manufacturer)
|
||||
{
|
||||
if (Resources.UpdateCompanyName(ExecutablePath, output, manufacturer))
|
||||
|
|
Loading…
Reference in New Issue