Added mechanism for package maintainers to produce a health check error.

Fixes #2049

(cherry picked from commit 7da02c236aa03e6aef011130526040c1cb8399fc)
(cherry picked from commit 024000275df3b2d3b884c2c2fbf0b86bd36a631a)
This commit is contained in:
Taloth Saldono 2021-03-06 22:47:02 +01:00 committed by Qstick
parent fa569f85b2
commit 5cc2db26e7
5 changed files with 79 additions and 6 deletions

View File

@ -53,7 +53,7 @@ namespace NzbDrone.Console
{
System.Console.WriteLine("");
System.Console.WriteLine("");
Logger.Fatal(ex.Message + ". This can happen if another instance of Lidarr is already running another application is using the same port (default: 8989) or the user has insufficient permissions");
Logger.Fatal(ex.Message + ". This can happen if another instance of Lidarr is already running another application is using the same port (default: 8686) or the user has insufficient permissions");
Exit(ExitCodes.RecoverableFailure, startupArgs);
}
catch (IOException ex)
@ -62,7 +62,7 @@ namespace NzbDrone.Console
{
System.Console.WriteLine("");
System.Console.WriteLine("");
Logger.Fatal(ex.Message + " This can happen if another instance of Radarr is already running another application is using the same port (default: 7878) or the user has insufficient permissions");
Logger.Fatal(ex.Message + " This can happen if another instance of Lidarr is already running another application is using the same port (default: 8686) or the user has insufficient permissions");
Exit(ExitCodes.RecoverableFailure, startupArgs);
}
else

View File

@ -68,6 +68,10 @@ namespace NzbDrone.Core.Test.UpdateTests
.Setup(c => c.FolderWritable(It.IsAny<string>()))
.Returns(true);
Mocker.GetMock<IDiskProvider>()
.Setup(v => v.FileExists(It.Is<string>(s => s.EndsWith("Lidarr.Update.exe"))))
.Returns(true);
_sandboxFolder = Mocker.GetMock<IAppFolderInfo>().Object.GetUpdateSandboxFolder();
}
@ -149,7 +153,7 @@ namespace NzbDrone.Core.Test.UpdateTests
}
[Test]
public void should_start_update_client()
public void should_start_update_client_if_updater_exists()
{
Subject.Execute(new ApplicationUpdateCommand());
@ -157,6 +161,21 @@ namespace NzbDrone.Core.Test.UpdateTests
.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("Lidarr.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()
{

View File

@ -12,6 +12,7 @@ namespace NzbDrone.Core.Configuration
{
string PackageVersion { get; }
string PackageAuthor { get; }
string PackageGlobalMessage { get; }
string PackageBranch { get; }
UpdateMechanism PackageUpdateMechanism { get; }
string PackageUpdateMechanismMessage { get; }
@ -41,6 +42,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");
@ -94,6 +96,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; }

View File

@ -0,0 +1,43 @@
using System;
using System.Linq;
using System.Text.RegularExpressions;
using NLog;
using NzbDrone.Common.Extensions;
using NzbDrone.Core.Configuration;
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");
}
}
}

View File

@ -146,16 +146,24 @@ namespace NzbDrone.Core.Update
_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("Lidarr will restart shortly.");
_processProvider.Start(_appFolderInfo.GetUpdateClientExePath(updatePackage.Runtime), GetUpdaterArgs(updateSandboxFolder));
_processProvider.Start(updateClientExePath, GetUpdaterArgs(updateSandboxFolder));
return true;
}