Add `dev kill` command

pull/642/head
NextTurn 2020-08-08 00:00:00 +08:00 committed by Next Turn
parent 788a0ff64b
commit 4414e36f6b
1 changed files with 29 additions and 0 deletions

View File

@ -285,6 +285,13 @@ namespace WinSW
}; };
dev.Add(ps); 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) 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) static void Customize(string output, string manufacturer)
{ {
if (Resources.UpdateCompanyName(ExecutablePath, output, manufacturer)) if (Resources.UpdateCompanyName(ExecutablePath, output, manufacturer))