public void Start(string installationFolder)
        {
            Verify(installationFolder);

            var appType = _detectApplicationType.GetAppType();

            try
            {
                _terminateNzbDrone.Terminate();

                _backupAndRestore.Backup(installationFolder);
                _backupAppData.Backup();

                _logger.Info("Moving update package to target");

                try
                {
                    _diskProvider.EmptyFolder(installationFolder);
                    _diskProvider.CopyFolder(_appFolderInfo.GetUpdatePackageFolder(), installationFolder);
                }
                catch (Exception e)
                {
                    _backupAndRestore.Restore(installationFolder);
                    _logger.FatalException("Failed to copy upgrade package to target folder.", e);
                }
            }
            finally
            {
                _startNzbDrone.Start(appType, installationFolder);
            }
        }
Exemple #2
0
        public void Start(string installationFolder, int processId)
        {
            _logger.Info("Installation Folder: {0}", installationFolder);
            _logger.Info("Updating Gamearr from version {0} to version {1}", _detectExistingVersion.GetExistingVersion(installationFolder), BuildInfo.Version);

            Verify(installationFolder, processId);

            var appType = _detectApplicationType.GetAppType();

            _processProvider.FindProcessByName(ProcessProvider.GAMEARR_CONSOLE_PROCESS_NAME);
            _processProvider.FindProcessByName(ProcessProvider.GAMEARR_PROCESS_NAME);

            if (OsInfo.IsWindows)
            {
                _terminateNzbDrone.Terminate(processId);
            }

            try
            {
                _backupAndRestore.Backup(installationFolder);
                _backupAppData.Backup();

                if (OsInfo.IsWindows)
                {
                    if (_processProvider.Exists(ProcessProvider.GAMEARR_CONSOLE_PROCESS_NAME) || _processProvider.Exists(ProcessProvider.GAMEARR_PROCESS_NAME))
                    {
                        _logger.Error("Gamearr was restarted prematurely by external process.");
                        return;
                    }
                }

                try
                {
                    _logger.Info("Copying new files to target folder");
                    _diskTransferService.MirrorFolder(_appFolderInfo.GetUpdatePackageFolder(), installationFolder);

                    // Set executable flag on Gamearr app
                    if (OsInfo.IsOsx)
                    {
                        _diskProvider.SetPermissions(Path.Combine(installationFolder, "Gamearr"), "0755", null, null);
                    }
                }
                catch (Exception e)
                {
                    _logger.Error(e, "Failed to copy upgrade package to target folder.");
                    _backupAndRestore.Restore(installationFolder);
                    throw;
                }
            }
            finally
            {
                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.GAMEARR_PROCESS_NAME))
                        {
                            _logger.Info("Gamearr was restarted by external process.");
                            break;
                        }
                    }

                    if (!_processProvider.Exists(ProcessProvider.GAMEARR_PROCESS_NAME))
                    {
                        _startNzbDrone.Start(appType, installationFolder);
                    }
                }
            }
        }
        public void Start(string installationFolder, int processId)
        {
            Verify(installationFolder, processId);

            var appType = _detectApplicationType.GetAppType();

            try
            {
                _processProvider.FindProcessByName(ProcessProvider.NZB_DRONE_CONSOLE_PROCESS_NAME);
                _processProvider.FindProcessByName(ProcessProvider.NZB_DRONE_PROCESS_NAME);

                if (OsInfo.IsWindows)
                {
                    _terminateNzbDrone.Terminate(processId);
                }

                _backupAndRestore.Backup(installationFolder);
                _backupAppData.Backup();

                try
                {
                    _logger.Info("Emptying installation folder");
                    _diskProvider.EmptyFolder(installationFolder);

                    _logger.Info("Copying new files to target folder");
                    _diskTransferService.TransferFolder(_appFolderInfo.GetUpdatePackageFolder(), installationFolder, TransferMode.Copy, false);

                    // Set executable flag on Sonarr app
                    if (OsInfo.IsOsx)
                    {
                        _diskProvider.SetPermissions(Path.Combine(installationFolder, "Sonarr"), "0755", null, null);
                    }
                }
                catch (Exception e)
                {
                    _logger.FatalException("Failed to copy upgrade package to target folder.", e);
                    _backupAndRestore.Restore(installationFolder);
                }
            }
            finally
            {
                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);
                    }
                }
            }
        }
        public void Start(string installationFolder, int processId)
        {
            _logger.Info("Installation Folder: {0}", installationFolder);
            _logger.Info("Updating Sonarr from version {0} to version {1}", _detectExistingVersion.GetExistingVersion(installationFolder), BuildInfo.Version);

            Verify(installationFolder, processId);

            if (installationFolder.EndsWith(@"\bin\Sonarr") || installationFolder.EndsWith(@"/bin/Sonarr"))
            {
                installationFolder = installationFolder.GetParentPath();
                _logger.Info("Fixed Installation Folder: {0}", installationFolder);
            }

            var appType = _detectApplicationType.GetAppType();

            _processProvider.FindProcessByName(ProcessProvider.SONARR_CONSOLE_PROCESS_NAME);
            _processProvider.FindProcessByName(ProcessProvider.SONARR_PROCESS_NAME);

            if (OsInfo.IsWindows)
            {
                _terminateNzbDrone.Terminate(processId);
            }

            try
            {
                _backupAndRestore.Backup(installationFolder);
                _backupAppData.Backup();

                if (OsInfo.IsWindows)
                {
                    if (_processProvider.Exists(ProcessProvider.SONARR_CONSOLE_PROCESS_NAME) || _processProvider.Exists(ProcessProvider.SONARR_PROCESS_NAME))
                    {
                        _logger.Error("Sonarr was restarted prematurely by external process.");
                        return;
                    }
                }

                try
                {
                    _logger.Info("Copying new files to target folder");
                    _diskTransferService.MirrorFolder(_appFolderInfo.GetUpdatePackageFolder(), installationFolder);

                    // Handle OSX package update and set executable flag on Sonarr app
                    if (OsInfo.IsOsx)
                    {
                        var shimPath     = Path.Combine(installationFolder, "Sonarr");
                        var realShimPath = Path.Combine(installationFolder, "../Sonarr");

                        if (installationFolder.EndsWith("/MacOS/bin") && _diskProvider.FileExists(realShimPath))
                        {
                            // New MacOS App stores Sonarr binaries in MacOS/bin and has a shim in MacOS
                            // Delete the shim in the downloaded update, we shouldn't update the shim unnecessarily
                            _diskProvider.DeleteFile(shimPath);
                        }
                        else
                        {
                            // Old MacOS App stores Sonarr binaries in MacOS together with shell script
                            // Make shim executable
                            _diskProvider.SetFilePermissions(shimPath, "755", null);
                        }
                    }
                }
                catch (Exception e)
                {
                    _logger.Error(e, "Failed to copy upgrade package to target folder.");
                    _backupAndRestore.Restore(installationFolder);
                    throw;
                }
            }
            finally
            {
                if (OsInfo.IsWindows)
                {
                    _startNzbDrone.Start(appType, installationFolder);
                }
                else
                {
                    _terminateNzbDrone.Terminate(processId);

                    _logger.Info("Waiting for external auto-restart.");
                    var theDakoLimit = 10;
                    for (int i = 0; i < theDakoLimit; i++)
                    {
                        System.Threading.Thread.Sleep(1000);

                        if (_processProvider.Exists(ProcessProvider.SONARR_PROCESS_NAME))
                        {
                            _logger.Info("Sonarr was restarted by external process.");
                            break;
                        }
                    }

                    if (!_processProvider.Exists(ProcessProvider.SONARR_PROCESS_NAME))
                    {
                        _startNzbDrone.Start(appType, installationFolder);
                    }
                }
            }
        }