From 060972475f13ffe59fcc09c51ffe91a547a29029 Mon Sep 17 00:00:00 2001 From: flightlevel Date: Tue, 26 Jun 2018 19:44:12 +1000 Subject: [PATCH 1/2] Windows Tray/Serice update improvements --- src/Jackett.Common/Services/UpdateService.cs | 23 ++++++++++---- src/Jackett.Service/Service.cs | 6 ++-- src/Jackett.Tray/Jackett.Tray.csproj | 6 ++++ src/Jackett.Tray/Main.cs | 12 +++++++- src/Jackett.Tray/Program.cs | 28 ++++++++++++++--- src/Jackett.Tray/TrayConsoleOptions.cs | 10 ++++++ src/Jackett.Updater/Program.cs | 32 +++++++++++++++++--- 7 files changed, 100 insertions(+), 17 deletions(-) create mode 100644 src/Jackett.Tray/TrayConsoleOptions.cs diff --git a/src/Jackett.Common/Services/UpdateService.cs b/src/Jackett.Common/Services/UpdateService.cs index a3c808d1d..56f538280 100644 --- a/src/Jackett.Common/Services/UpdateService.cs +++ b/src/Jackett.Common/Services/UpdateService.cs @@ -270,15 +270,27 @@ namespace Jackett.Common.Services private void StartUpdate(string updaterExePath, string installLocation, bool isWindows, bool NoRestart, bool trayWasRunning) { + string appType = "Console"; + //DI once off Owin + IProcessService processService = new ProcessService(logger); + IServiceConfigService windowsService = new WindowsServiceConfigService(processService, logger); + + if (isWindows && windowsService.ServiceExists()) + { + appType = "WindowsService"; + } + var exe = Path.GetFileName(ExePath()); var args = string.Join(" ", Environment.GetCommandLineArgs().Skip(1).Select(a => a.Contains(" ") ? "\"" +a + "\"" : a )).Replace("\"", "\\\""); var startInfo = new ProcessStartInfo(); + startInfo.UseShellExecute = false; + startInfo.CreateNoWindow = true; // Note: add a leading space to the --Args argument to avoid parsing as arguments if (isWindows) { - startInfo.Arguments = $"--Path \"{installLocation}\" --Type \"{exe}\" --Args \" {args}\""; + startInfo.Arguments = $"--Path \"{installLocation}\" --Type \"{appType}\" --Args \" {args}\""; startInfo.FileName = Path.Combine(updaterExePath); } else @@ -287,13 +299,12 @@ namespace Jackett.Common.Services args = exe + " " + args; exe = "mono"; - startInfo.Arguments = $"{Path.Combine(updaterExePath)} --Path \"{installLocation}\" --Type \"{exe}\" --Args \" {args}\""; + startInfo.Arguments = $"{Path.Combine(updaterExePath)} --Path \"{installLocation}\" --Type \"{appType}\" --Args \" {args}\""; startInfo.FileName = "mono"; - startInfo.UseShellExecute = false; - startInfo.CreateNoWindow = true; } - try { + try + { var pid = Process.GetCurrentProcess().Id; startInfo.Arguments += $" --KillPids \"{pid}\""; } @@ -317,7 +328,7 @@ namespace Jackett.Common.Services var procInfo = Process.Start(startInfo); logger.Info($"Updater started process id: {procInfo.Id}"); if (NoRestart == false) - { + { logger.Info("Exiting Jackett.."); lockService.Signal(); //TODO: Remove once off Owin diff --git a/src/Jackett.Service/Service.cs b/src/Jackett.Service/Service.cs index ba95ec746..7fdd7fd22 100644 --- a/src/Jackett.Service/Service.cs +++ b/src/Jackett.Service/Service.cs @@ -77,10 +77,12 @@ namespace Jackett.Service private void ProcessExited(object sender, EventArgs e) { + logger.Info("Console process exited"); + if (!serviceStopInitiated) { logger.Info("Service stop not responsible for process exit"); - OnStop(); + Stop(); } } @@ -89,7 +91,7 @@ namespace Jackett.Service if (consoleProcess != null && !consoleProcess.HasExited) { consoleProcess.StandardInput.Close(); - System.Threading.Thread.Sleep(1000); + consoleProcess.WaitForExit(2000); if (consoleProcess != null && !consoleProcess.HasExited) { consoleProcess.Kill(); diff --git a/src/Jackett.Tray/Jackett.Tray.csproj b/src/Jackett.Tray/Jackett.Tray.csproj index f48380428..88c8c5d10 100644 --- a/src/Jackett.Tray/Jackett.Tray.csproj +++ b/src/Jackett.Tray/Jackett.Tray.csproj @@ -66,6 +66,7 @@ + Main.cs @@ -109,6 +110,11 @@ True + + + 2.2.1 + +