From 7d23f24854854b41faaf3e7574dd64f89e3b1ad6 Mon Sep 17 00:00:00 2001 From: Taloth Saldono Date: Sat, 16 May 2015 01:32:35 +0200 Subject: [PATCH] New: Hand-off update logic to handle upstart/systemd and other auto-restart mechanisms. --- .../UpdateEngine/InstallUpdateService.cs | 35 ++++++++++++++++--- 1 file changed, 31 insertions(+), 4 deletions(-) diff --git a/src/NzbDrone.Update/UpdateEngine/InstallUpdateService.cs b/src/NzbDrone.Update/UpdateEngine/InstallUpdateService.cs index 1e6a53821..cbad5d493 100644 --- a/src/NzbDrone.Update/UpdateEngine/InstallUpdateService.cs +++ b/src/NzbDrone.Update/UpdateEngine/InstallUpdateService.cs @@ -79,7 +79,10 @@ public void Start(string installationFolder, int processId) try { - _terminateNzbDrone.Terminate(processId); + if (OsInfo.IsWindows) + { + _terminateNzbDrone.Terminate(processId); + } _backupAndRestore.Backup(installationFolder); _backupAppData.Backup(); @@ -92,10 +95,10 @@ public void Start(string installationFolder, int processId) _logger.Info("Copying new files to target folder"); _diskProvider.CopyFolder(_appFolderInfo.GetUpdatePackageFolder(), installationFolder); - // Set executable flag on SOnarr app + // Set executable flag on Sonarr app if (OsInfo.IsOsx) { - _diskProvider.SetPermissions(Path.Combine(installationFolder, "Sonarr"), "0755", null, null); + _diskProvider.SetPermissions(Path.Combine(installationFolder, "Sonarr"), "0755", null, null); } } catch (Exception e) @@ -106,7 +109,31 @@ public void Start(string installationFolder, int processId) } finally { - _startNzbDrone.Start(appType, installationFolder); + if (OsInfo.IsWindows) + { + _startNzbDrone.Start(appType, installationFolder); + } + else + { + _terminateNzbDrone.Terminate(processId); + + _logger.Info("Waiting for external auto-restart."); + for (int i = 0; i < 5; i++) + { + System.Threading.Thread.Sleep(1000); + + if (_processProvider.Exists(ProcessProvider.NZB_DRONE_PROCESS_NAME)) + { + _logger.Info("Sonarr was restarted by external process."); + break; + } + } + + if (!_processProvider.Exists(ProcessProvider.NZB_DRONE_PROCESS_NAME)) + { + _startNzbDrone.Start(appType, installationFolder); + } + } } }