From 1eb6629088e4e648d5140b4ba794df28f4f103dd Mon Sep 17 00:00:00 2001 From: Taloth Saldono Date: Wed, 8 Jul 2015 20:54:47 +0200 Subject: [PATCH] Fixed: Updater occasionally killed Sonarr twice before allowing it to be restarted by upstart. Fixed: Updater killed itself during update on debian jessie. --- .../Processes/ProcessProvider.cs | 18 ++++++++++++++++++ .../UpdateEngine/InstallUpdateService.cs | 3 +++ .../UpdateEngine/TerminateNzbDrone.cs | 15 ++++++++++----- 3 files changed, 31 insertions(+), 5 deletions(-) diff --git a/src/NzbDrone.Common/Processes/ProcessProvider.cs b/src/NzbDrone.Common/Processes/ProcessProvider.cs index 9a4fef4dd..7289ebbdc 100644 --- a/src/NzbDrone.Common/Processes/ProcessProvider.cs +++ b/src/NzbDrone.Common/Processes/ProcessProvider.cs @@ -244,6 +244,12 @@ public void KillAll(string processName) foreach (var processInfo in processes) { + if (processInfo.Id == Process.GetCurrentProcess().Id) + { + _logger.Debug("Tried killing own process, skipping: {0} [{1}]", processInfo.Id, processInfo.ProcessName); + continue; + } + _logger.Debug("Killing process: {0} [{1}]", processInfo.Id, processInfo.ProcessName); Kill(processInfo.Id); } @@ -306,6 +312,18 @@ private List GetProcessesByName(string name) _logger.Debug("Found {0} processes with the name: {1}", processes.Count, name); + try + { + foreach (var process in processes) + { + _logger.Debug(" - [{0}] {1}", process.Id, process.ProcessName); + } + } + catch + { + // Don't crash on gettings some log data. + } + return processes; } diff --git a/src/NzbDrone.Update/UpdateEngine/InstallUpdateService.cs b/src/NzbDrone.Update/UpdateEngine/InstallUpdateService.cs index ef511227f..f12f54dae 100644 --- a/src/NzbDrone.Update/UpdateEngine/InstallUpdateService.cs +++ b/src/NzbDrone.Update/UpdateEngine/InstallUpdateService.cs @@ -82,6 +82,9 @@ public void Start(string installationFolder, int processId) try { + _processProvider.FindProcessByName(ProcessProvider.NZB_DRONE_CONSOLE_PROCESS_NAME); + _processProvider.FindProcessByName(ProcessProvider.NZB_DRONE_PROCESS_NAME); + if (OsInfo.IsWindows) { _terminateNzbDrone.Terminate(processId); diff --git a/src/NzbDrone.Update/UpdateEngine/TerminateNzbDrone.cs b/src/NzbDrone.Update/UpdateEngine/TerminateNzbDrone.cs index 875e227a8..2033ec2d2 100644 --- a/src/NzbDrone.Update/UpdateEngine/TerminateNzbDrone.cs +++ b/src/NzbDrone.Update/UpdateEngine/TerminateNzbDrone.cs @@ -44,16 +44,21 @@ public void Terminate(int processId) _logger.ErrorException("couldn't stop service", e); } } + + _logger.Info("Killing all running processes"); + + _processProvider.KillAll(ProcessProvider.NZB_DRONE_CONSOLE_PROCESS_NAME); + _processProvider.KillAll(ProcessProvider.NZB_DRONE_PROCESS_NAME); } else { + _logger.Info("Killing all running processes"); + + _processProvider.KillAll(ProcessProvider.NZB_DRONE_CONSOLE_PROCESS_NAME); + _processProvider.KillAll(ProcessProvider.NZB_DRONE_PROCESS_NAME); + _processProvider.Kill(processId); } - - _logger.Info("Killing all running processes"); - - _processProvider.KillAll(ProcessProvider.NZB_DRONE_CONSOLE_PROCESS_NAME); - _processProvider.KillAll(ProcessProvider.NZB_DRONE_PROCESS_NAME); } } } \ No newline at end of file