From aba9e6db479abdeb1b1b1ae7e2c08c8ff943e176 Mon Sep 17 00:00:00 2001 From: kaso17 Date: Mon, 3 Sep 2018 16:35:56 +0200 Subject: [PATCH] Updater: try SIGTERM first --- src/Jackett.Updater/Program.cs | 29 ++++++++++++++++++++++++++--- 1 file changed, 26 insertions(+), 3 deletions(-) diff --git a/src/Jackett.Updater/Program.cs b/src/Jackett.Updater/Program.cs index 8e6de9c86..ff4f45ff9 100644 --- a/src/Jackett.Updater/Program.cs +++ b/src/Jackett.Updater/Program.cs @@ -87,10 +87,33 @@ namespace Jackett.Updater { var proc = Process.GetProcessById(pid); logger.Info("Killing process " + proc.Id); - proc.Kill(); - var exited = proc.WaitForExit(5000); + + // try to kill gracefully (on unix) first, see #3692 + var exited = false; + if (Environment.OSVersion.Platform == PlatformID.Unix) + { + try + { + var startInfo = new ProcessStartInfo(); + startInfo.Arguments = "-15 " + pid; + startInfo.FileName = "kill"; + Process.Start(startInfo); + exited = proc.WaitForExit(5000); + } + catch (Exception e) + { + logger.Error(e, "Error while sending SIGTERM to " + pid.ToString()); + } + if (!exited) + logger.Info("Process " + pid.ToString() + " didn't exit within 5 seconds after a SIGTERM"); + } if (!exited) - logger.Info("Process " + pid.ToString() + " didn't exit within 5 seconds"); + { + proc.Kill(); // send SIGKILL + } + exited = proc.WaitForExit(5000); + if (!exited) + logger.Info("Process " + pid.ToString() + " didn't exit within 5 seconds after a SIGKILL"); } catch (ArgumentException) {