mirror of
https://github.com/lidarr/Lidarr
synced 2024-12-25 01:02:05 +00:00
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:
parent
fa569f85b2
commit
5cc2db26e7
5 changed files with 79 additions and 6 deletions
|
@ -53,7 +53,7 @@ public static void Main(string[] args)
|
|||
{
|
||||
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 @@ public static void Main(string[] args)
|
|||
{
|
||||
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
|
||||
|
|
|
@ -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("Lidarr.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("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()
|
||||
{
|
||||
|
|
|
@ -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,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");
|
||||
}
|
||||
}
|
||||
}
|
|
@ -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("Lidarr will restart shortly.");
|
||||
|
||||
_processProvider.Start(_appFolderInfo.GetUpdateClientExePath(updatePackage.Runtime), GetUpdaterArgs(updateSandboxFolder));
|
||||
_processProvider.Start(updateClientExePath, GetUpdaterArgs(updateSandboxFolder));
|
||||
|
||||
return true;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue