|
|
@ -18,6 +18,7 @@ namespace NzbDrone.Update.UpdateEngine
|
|
|
|
private readonly IDiskProvider _diskProvider;
|
|
|
|
private readonly IDiskProvider _diskProvider;
|
|
|
|
private readonly IDiskTransferService _diskTransferService;
|
|
|
|
private readonly IDiskTransferService _diskTransferService;
|
|
|
|
private readonly IDetectApplicationType _detectApplicationType;
|
|
|
|
private readonly IDetectApplicationType _detectApplicationType;
|
|
|
|
|
|
|
|
private readonly IDetectExistingVersion _detectExistingVersion;
|
|
|
|
private readonly ITerminateNzbDrone _terminateNzbDrone;
|
|
|
|
private readonly ITerminateNzbDrone _terminateNzbDrone;
|
|
|
|
private readonly IAppFolderInfo _appFolderInfo;
|
|
|
|
private readonly IAppFolderInfo _appFolderInfo;
|
|
|
|
private readonly IBackupAndRestore _backupAndRestore;
|
|
|
|
private readonly IBackupAndRestore _backupAndRestore;
|
|
|
@ -29,6 +30,7 @@ namespace NzbDrone.Update.UpdateEngine
|
|
|
|
public InstallUpdateService(IDiskProvider diskProvider,
|
|
|
|
public InstallUpdateService(IDiskProvider diskProvider,
|
|
|
|
IDiskTransferService diskTransferService,
|
|
|
|
IDiskTransferService diskTransferService,
|
|
|
|
IDetectApplicationType detectApplicationType,
|
|
|
|
IDetectApplicationType detectApplicationType,
|
|
|
|
|
|
|
|
IDetectExistingVersion detectExistingVersion,
|
|
|
|
ITerminateNzbDrone terminateNzbDrone,
|
|
|
|
ITerminateNzbDrone terminateNzbDrone,
|
|
|
|
IAppFolderInfo appFolderInfo,
|
|
|
|
IAppFolderInfo appFolderInfo,
|
|
|
|
IBackupAndRestore backupAndRestore,
|
|
|
|
IBackupAndRestore backupAndRestore,
|
|
|
@ -40,6 +42,7 @@ namespace NzbDrone.Update.UpdateEngine
|
|
|
|
_diskProvider = diskProvider;
|
|
|
|
_diskProvider = diskProvider;
|
|
|
|
_diskTransferService = diskTransferService;
|
|
|
|
_diskTransferService = diskTransferService;
|
|
|
|
_detectApplicationType = detectApplicationType;
|
|
|
|
_detectApplicationType = detectApplicationType;
|
|
|
|
|
|
|
|
_detectExistingVersion = detectExistingVersion;
|
|
|
|
_terminateNzbDrone = terminateNzbDrone;
|
|
|
|
_terminateNzbDrone = terminateNzbDrone;
|
|
|
|
_appFolderInfo = appFolderInfo;
|
|
|
|
_appFolderInfo = appFolderInfo;
|
|
|
|
_backupAndRestore = backupAndRestore;
|
|
|
|
_backupAndRestore = backupAndRestore;
|
|
|
@ -76,30 +79,42 @@ namespace NzbDrone.Update.UpdateEngine
|
|
|
|
|
|
|
|
|
|
|
|
public void Start(string installationFolder, int processId)
|
|
|
|
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);
|
|
|
|
Verify(installationFolder, processId);
|
|
|
|
|
|
|
|
|
|
|
|
var appType = _detectApplicationType.GetAppType();
|
|
|
|
var appType = _detectApplicationType.GetAppType();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
_processProvider.FindProcessByName(ProcessProvider.NZB_DRONE_CONSOLE_PROCESS_NAME);
|
|
|
|
|
|
|
|
_processProvider.FindProcessByName(ProcessProvider.NZB_DRONE_PROCESS_NAME);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (OsInfo.IsWindows)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
_terminateNzbDrone.Terminate(processId);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
try
|
|
|
|
try
|
|
|
|
{
|
|
|
|
{
|
|
|
|
_processProvider.FindProcessByName(ProcessProvider.NZB_DRONE_CONSOLE_PROCESS_NAME);
|
|
|
|
_backupAndRestore.Backup(installationFolder);
|
|
|
|
_processProvider.FindProcessByName(ProcessProvider.NZB_DRONE_PROCESS_NAME);
|
|
|
|
_backupAppData.Backup();
|
|
|
|
|
|
|
|
|
|
|
|
if (OsInfo.IsWindows)
|
|
|
|
if (OsInfo.IsWindows)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
_terminateNzbDrone.Terminate(processId);
|
|
|
|
if (_processProvider.Exists(ProcessProvider.NZB_DRONE_CONSOLE_PROCESS_NAME) || _processProvider.Exists(ProcessProvider.NZB_DRONE_PROCESS_NAME))
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
_logger.Error("Sonarr was restarted prematurely by external process.");
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
_backupAndRestore.Backup(installationFolder);
|
|
|
|
|
|
|
|
_backupAppData.Backup();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
try
|
|
|
|
try
|
|
|
|
{
|
|
|
|
{
|
|
|
|
_logger.Info("Emptying installation folder");
|
|
|
|
_logger.Info("Emptying installation folder");
|
|
|
|
_diskProvider.EmptyFolder(installationFolder);
|
|
|
|
_diskProvider.EmptyFolder(installationFolder);
|
|
|
|
|
|
|
|
|
|
|
|
_logger.Info("Copying new files to target folder");
|
|
|
|
_logger.Info("Copying new files to target folder");
|
|
|
|
_diskTransferService.TransferFolder(_appFolderInfo.GetUpdatePackageFolder(), installationFolder, TransferMode.Copy, false);
|
|
|
|
_diskTransferService.MirrorFolder(_appFolderInfo.GetUpdatePackageFolder(), installationFolder);
|
|
|
|
|
|
|
|
|
|
|
|
// Set executable flag on Sonarr app
|
|
|
|
// Set executable flag on Sonarr app
|
|
|
|
if (OsInfo.IsOsx)
|
|
|
|
if (OsInfo.IsOsx)
|
|
|
@ -109,8 +124,9 @@ namespace NzbDrone.Update.UpdateEngine
|
|
|
|
}
|
|
|
|
}
|
|
|
|
catch (Exception e)
|
|
|
|
catch (Exception e)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
_logger.Fatal(e, "Failed to copy upgrade package to target folder.");
|
|
|
|
_logger.Error(e, "Failed to copy upgrade package to target folder.");
|
|
|
|
_backupAndRestore.Restore(installationFolder);
|
|
|
|
_backupAndRestore.Restore(installationFolder);
|
|
|
|
|
|
|
|
throw;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
finally
|
|
|
|
finally
|
|
|
|