mirror of
https://github.com/Radarr/Radarr
synced 2025-02-25 07:32:56 +00:00
Added mechanism for package maintainers to produce a health check error.
(cherry picked from commit 7da02c236aa03e6aef011130526040c1cb8399fc)
This commit is contained in:
parent
a3723b5ad7
commit
024000275d
4 changed files with 79 additions and 4 deletions
|
@ -68,6 +68,10 @@ public void Setup()
|
|||
.Setup(c => c.FolderWritable(It.IsAny<string>()))
|
||||
.Returns(true);
|
||||
|
||||
Mocker.GetMock<IDiskProvider>()
|
||||
.Setup(v => v.FileExists(It.Is<string>(s => s.EndsWith("Radarr.Update.exe"))))
|
||||
.Returns(true);
|
||||
|
||||
_sandboxFolder = Mocker.GetMock<IAppFolderInfo>().Object.GetUpdateSandboxFolder();
|
||||
}
|
||||
|
||||
|
@ -149,7 +153,7 @@ public void Should_copy_update_client_to_root_of_sandbox()
|
|||
}
|
||||
|
||||
[Test]
|
||||
public void should_start_update_client()
|
||||
public void should_start_update_client_if_updater_exists()
|
||||
{
|
||||
Subject.Execute(new ApplicationUpdateCommand());
|
||||
|
||||
|
@ -157,6 +161,21 @@ public void should_start_update_client()
|
|||
.Verify(c => c.Start(It.IsAny<string>(), It.Is<string>(s => s.StartsWith("12")), null, null, null), Times.Once());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_return_with_warning_if_updater_doesnt_exists()
|
||||
{
|
||||
Mocker.GetMock<IDiskProvider>()
|
||||
.Setup(v => v.FileExists(It.Is<string>(s => s.EndsWith("Radarr.Update.exe"))))
|
||||
.Returns(false);
|
||||
|
||||
Subject.Execute(new ApplicationUpdateCommand());
|
||||
|
||||
Mocker.GetMock<IProcessProvider>()
|
||||
.Verify(c => c.Start(It.IsAny<string>(), It.IsAny<string>(), null, null, null), Times.Never());
|
||||
|
||||
ExceptionVerification.ExpectedWarns(1);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_return_without_error_or_warnings_when_no_updates_are_available()
|
||||
{
|
||||
|
|
|
@ -12,6 +12,7 @@ public interface IDeploymentInfoProvider
|
|||
{
|
||||
string PackageVersion { get; }
|
||||
string PackageAuthor { get; }
|
||||
string PackageGlobalMessage { get; }
|
||||
string PackageBranch { get; }
|
||||
UpdateMechanism PackageUpdateMechanism { get; }
|
||||
string PackageUpdateMechanismMessage { get; }
|
||||
|
@ -41,6 +42,7 @@ public DeploymentInfoProvider(IAppFolderInfo appFolderInfo, IDiskProvider diskPr
|
|||
|
||||
PackageVersion = ReadValue(data, "PackageVersion");
|
||||
PackageAuthor = ReadValue(data, "PackageAuthor");
|
||||
PackageGlobalMessage = ReadValue(data, "PackageGlobalMessage");
|
||||
PackageUpdateMechanism = ReadEnumValue(data, "UpdateMethod", UpdateMechanism.BuiltIn);
|
||||
PackageUpdateMechanismMessage = ReadValue(data, "UpdateMethodMessage");
|
||||
PackageBranch = ReadValue(data, "Branch");
|
||||
|
@ -94,6 +96,7 @@ private static T ReadEnumValue<T>(string fileData, string key, T defaultValue)
|
|||
|
||||
public string PackageVersion { get; private set; }
|
||||
public string PackageAuthor { get; private set; }
|
||||
public string PackageGlobalMessage { get; private set; }
|
||||
public string PackageBranch { get; private set; }
|
||||
public UpdateMechanism PackageUpdateMechanism { get; private set; }
|
||||
public string PackageUpdateMechanismMessage { get; private set; }
|
||||
|
|
|
@ -0,0 +1,45 @@
|
|||
using System;
|
||||
using System.Linq;
|
||||
using System.Text.RegularExpressions;
|
||||
using NLog;
|
||||
using NzbDrone.Common.Extensions;
|
||||
using NzbDrone.Core.Configuration;
|
||||
using NzbDrone.Core.Localization;
|
||||
|
||||
namespace NzbDrone.Core.HealthCheck.Checks
|
||||
{
|
||||
public class PackageGlobalMessageCheck : HealthCheckBase
|
||||
{
|
||||
private readonly IDeploymentInfoProvider _deploymentInfoProvider;
|
||||
|
||||
public PackageGlobalMessageCheck(IDeploymentInfoProvider deploymentInfoProvider, ILocalizationService localizationService)
|
||||
: base(localizationService)
|
||||
{
|
||||
_deploymentInfoProvider = deploymentInfoProvider;
|
||||
}
|
||||
|
||||
public override HealthCheck Check()
|
||||
{
|
||||
if (_deploymentInfoProvider.PackageGlobalMessage.IsNullOrWhiteSpace())
|
||||
{
|
||||
return new HealthCheck(GetType());
|
||||
}
|
||||
|
||||
var message = _deploymentInfoProvider.PackageGlobalMessage;
|
||||
HealthCheckResult result = HealthCheckResult.Notice;
|
||||
|
||||
if (message.StartsWith("Error:"))
|
||||
{
|
||||
message = message.Substring(6);
|
||||
result = HealthCheckResult.Error;
|
||||
}
|
||||
else if (message.StartsWith("Warn:"))
|
||||
{
|
||||
message = message.Substring(5);
|
||||
result = HealthCheckResult.Warning;
|
||||
}
|
||||
|
||||
return new HealthCheck(GetType(), result, message, "#package_maintainer_message");
|
||||
}
|
||||
}
|
||||
}
|
|
@ -146,16 +146,24 @@ private bool InstallUpdate(UpdatePackage updatePackage)
|
|||
_logger.Info("Preparing client");
|
||||
_diskTransferService.TransferFolder(_appFolderInfo.GetUpdateClientFolder(), updateSandboxFolder, TransferMode.Move);
|
||||
|
||||
var updateClientExePath = _appFolderInfo.GetUpdateClientExePath(updatePackage.Runtime);
|
||||
|
||||
if (!_diskProvider.FileExists(updateClientExePath))
|
||||
{
|
||||
_logger.Warn("Update client {0} does not exist, aborting update.", updateClientExePath);
|
||||
return false;
|
||||
}
|
||||
|
||||
// Set executable flag on update app
|
||||
if (OsInfo.IsOsx || (OsInfo.IsLinux && PlatformInfo.IsNetCore))
|
||||
{
|
||||
_diskProvider.SetFilePermissions(_appFolderInfo.GetUpdateClientExePath(updatePackage.Runtime), "755", null);
|
||||
_diskProvider.SetFilePermissions(updateClientExePath, "755", null);
|
||||
}
|
||||
|
||||
_logger.Info("Starting update client {0}", _appFolderInfo.GetUpdateClientExePath(updatePackage.Runtime));
|
||||
_logger.Info("Starting update client {0}", updateClientExePath);
|
||||
_logger.ProgressInfo("Radarr will restart shortly.");
|
||||
|
||||
_processProvider.Start(_appFolderInfo.GetUpdateClientExePath(updatePackage.Runtime), GetUpdaterArgs(updateSandboxFolder));
|
||||
_processProvider.Start(updateClientExePath, GetUpdaterArgs(updateSandboxFolder));
|
||||
|
||||
return true;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue