From 7da02c236aa03e6aef011130526040c1cb8399fc Mon Sep 17 00:00:00 2001 From: Taloth Saldono Date: Sat, 6 Mar 2021 22:47:02 +0100 Subject: [PATCH] Added mechanism for package maintainers to produce a health check error. --- .../UpdatePackageProviderFixture.cs | 4 +- .../Configuration/ConfigFileProvider.cs | 2 +- .../Configuration/DeploymentInfoProvider.cs | 5 +- .../Checks/PackageGlobalMessageCheck.cs | 46 +++++++++++++++++++ .../Update/InstallUpdateService.cs | 12 ++++- 5 files changed, 63 insertions(+), 6 deletions(-) create mode 100644 src/NzbDrone.Core/HealthCheck/Checks/PackageGlobalMessageCheck.cs diff --git a/src/NzbDrone.Core.Test/UpdateTests/UpdatePackageProviderFixture.cs b/src/NzbDrone.Core.Test/UpdateTests/UpdatePackageProviderFixture.cs index 92d51a64e..362355ebf 100644 --- a/src/NzbDrone.Core.Test/UpdateTests/UpdatePackageProviderFixture.cs +++ b/src/NzbDrone.Core.Test/UpdateTests/UpdatePackageProviderFixture.cs @@ -21,14 +21,14 @@ namespace NzbDrone.Core.Test.UpdateTests public void no_update_when_version_higher() { UseRealHttp(); - Subject.GetLatestUpdate("master", new Version(10, 0)).Should().BeNull(); + Subject.GetLatestUpdate("main", new Version(10, 0)).Should().BeNull(); } [Test] public void finds_update_when_version_lower() { UseRealHttp(); - Subject.GetLatestUpdate("master", new Version(3, 0)).Should().NotBeNull(); + Subject.GetLatestUpdate("main", new Version(3, 0)).Should().NotBeNull(); } [Test] diff --git a/src/NzbDrone.Core/Configuration/ConfigFileProvider.cs b/src/NzbDrone.Core/Configuration/ConfigFileProvider.cs index 209c0f7fa..556050b9a 100644 --- a/src/NzbDrone.Core/Configuration/ConfigFileProvider.cs +++ b/src/NzbDrone.Core/Configuration/ConfigFileProvider.cs @@ -177,7 +177,7 @@ namespace NzbDrone.Core.Configuration public bool AnalyticsEnabled => GetValueBoolean("AnalyticsEnabled", true, persist: false); - public string Branch => GetValue("Branch", "master").ToLowerInvariant(); + public string Branch => GetValue("Branch", "main").ToLowerInvariant(); public string LogLevel => GetValue("LogLevel", "info"); public string ConsoleLogLevel => GetValue("ConsoleLogLevel", string.Empty, persist: false); diff --git a/src/NzbDrone.Core/Configuration/DeploymentInfoProvider.cs b/src/NzbDrone.Core/Configuration/DeploymentInfoProvider.cs index ff812527a..876fee42d 100644 --- a/src/NzbDrone.Core/Configuration/DeploymentInfoProvider.cs +++ b/src/NzbDrone.Core/Configuration/DeploymentInfoProvider.cs @@ -16,6 +16,7 @@ namespace NzbDrone.Core.Configuration { string PackageVersion { get; } string PackageAuthor { get; } + string PackageGlobalMessage { get; } string PackageBranch { get; } UpdateMechanism PackageUpdateMechanism { get; } string PackageUpdateMechanismMessage { get; } @@ -37,7 +38,7 @@ namespace NzbDrone.Core.Configuration var releaseInfoPath = Path.Combine(bin, "release_info"); PackageUpdateMechanism = UpdateMechanism.BuiltIn; - DefaultBranch = "master"; + DefaultBranch = "main"; if (Path.GetFileName(bin) == "bin" && diskProvider.FileExists(packageInfoPath)) { @@ -45,6 +46,7 @@ namespace NzbDrone.Core.Configuration 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"); @@ -98,6 +100,7 @@ namespace NzbDrone.Core.Configuration 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; } diff --git a/src/NzbDrone.Core/HealthCheck/Checks/PackageGlobalMessageCheck.cs b/src/NzbDrone.Core/HealthCheck/Checks/PackageGlobalMessageCheck.cs new file mode 100644 index 000000000..665acc450 --- /dev/null +++ b/src/NzbDrone.Core/HealthCheck/Checks/PackageGlobalMessageCheck.cs @@ -0,0 +1,46 @@ +using System; +using System.Linq; +using System.Text.RegularExpressions; +using NLog; +using NzbDrone.Common.Extensions; +using NzbDrone.Core.Configuration; +using NzbDrone.Core.Download; +using NzbDrone.Core.ThingiProvider.Events; + +namespace NzbDrone.Core.HealthCheck.Checks +{ + public class PackageGlobalMessageCheck : HealthCheckBase + { + private readonly IDeploymentInfoProvider _deploymentInfoProvider; + + + public PackageGlobalMessageCheck(IDeploymentInfoProvider deploymentInfoProvider) + { + _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"); + } + } +} diff --git a/src/NzbDrone.Core/Update/InstallUpdateService.cs b/src/NzbDrone.Core/Update/InstallUpdateService.cs index 9244b9d73..6dd2934ea 100644 --- a/src/NzbDrone.Core/Update/InstallUpdateService.cs +++ b/src/NzbDrone.Core/Update/InstallUpdateService.cs @@ -143,10 +143,18 @@ namespace NzbDrone.Core.Update _logger.Info("Preparing client"); _diskTransferService.TransferFolder(_appFolderInfo.GetUpdateClientFolder(), updateSandboxFolder, TransferMode.Move); - _logger.Info("Starting update client {0}", _appFolderInfo.GetUpdateClientExePath()); + var updateClientExePath = _appFolderInfo.GetUpdateClientExePath(); + + if (!_diskProvider.FileExists(updateClientExePath)) + { + _logger.Warn("Update client {0} does not exist, aborting update.", updateClientExePath); + return false; + } + + _logger.Info("Starting update client {0}", updateClientExePath); _logger.ProgressInfo("Sonarr will restart shortly."); - _processProvider.Start(_appFolderInfo.GetUpdateClientExePath(), GetUpdaterArgs(updateSandboxFolder)); + _processProvider.Start(updateClientExePath, GetUpdaterArgs(updateSandboxFolder)); return true; }