protected override Task<ResultStatus> DoCommandOverride(ICommandContext commandContext) { logger = commandContext.Logger; if (!File.Exists(ProcessPath)) { logger.Error("Unable to find binary file " + ProcessPath); return Task.FromResult(ResultStatus.Failed); } var startInfo = new ProcessStartInfo { FileName = ProcessPath, Arguments = Arguments, WorkingDirectory = ".", UseShellExecute = false, RedirectStandardOutput = true }; process = Process.Start(startInfo); process.OutputDataReceived += OnOutputDataReceived; process.BeginOutputReadLine(); process.WaitForExit(); ExitCode = process.ExitCode; return Task.FromResult(CancellationToken.IsCancellationRequested ? ResultStatus.Cancelled : (ExitCode == 0 ? ResultStatus.Successful : ResultStatus.Failed)); }
private static void RestartService(Logger log, string serviceName, int timeout) { var serviceController = new ServiceController(serviceName); try { serviceController.Stop(); serviceController.WaitForStatus(ServiceControllerStatus.Stopped, TimeSpan.FromMilliseconds(timeout)); serviceController.Start(); serviceController.WaitForStatus(ServiceControllerStatus.Running, TimeSpan.FromMilliseconds(timeout)); } catch { log.Error("Error restarting {0} service", serviceName); } }