mirror of
https://github.com/Radarr/Radarr.git
synced 2024-11-10 13:02:47 +01:00
When restarting after update if service start fails update app will fallback to console.
This commit is contained in:
parent
44ff12eaaa
commit
d0d95602c6
@ -9,10 +9,8 @@
|
|||||||
namespace NzbDrone.Update.Test
|
namespace NzbDrone.Update.Test
|
||||||
{
|
{
|
||||||
[TestFixture]
|
[TestFixture]
|
||||||
public class UpdateProviderVerifyFixture : TestBase
|
public class InstallUpdateServiceFixture : TestBase<InstallUpdateService>
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|
||||||
[SetUp]
|
[SetUp]
|
||||||
public void Setup()
|
public void Setup()
|
||||||
{
|
{
|
||||||
@ -25,7 +23,7 @@ public void Setup()
|
|||||||
[TestCase(" ")]
|
[TestCase(" ")]
|
||||||
public void update_should_throw_target_folder_is_blank(string target)
|
public void update_should_throw_target_folder_is_blank(string target)
|
||||||
{
|
{
|
||||||
Assert.Throws<ArgumentException>(() => Mocker.Resolve<InstallUpdateService>().Start(target))
|
Assert.Throws<ArgumentException>(() => Subject.Start(target))
|
||||||
.Message.Should().StartWith("Target folder can not be null or empty");
|
.Message.Should().StartWith("Target folder can not be null or empty");
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -34,7 +32,7 @@ public void update_should_throw_if_target_folder_doesnt_exist()
|
|||||||
{
|
{
|
||||||
string targetFolder = "c:\\NzbDrone\\";
|
string targetFolder = "c:\\NzbDrone\\";
|
||||||
|
|
||||||
Assert.Throws<DirectoryNotFoundException>(() => Mocker.Resolve<InstallUpdateService>().Start(targetFolder))
|
Assert.Throws<DirectoryNotFoundException>(() => Subject.Start(targetFolder))
|
||||||
.Message.Should().StartWith("Target folder doesn't exist");
|
.Message.Should().StartWith("Target folder doesn't exist");
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -52,7 +50,7 @@ public void update_should_throw_if_update_folder_doesnt_exist()
|
|||||||
.Setup(c => c.FolderExists(sandboxFolder))
|
.Setup(c => c.FolderExists(sandboxFolder))
|
||||||
.Returns(false);
|
.Returns(false);
|
||||||
|
|
||||||
Assert.Throws<DirectoryNotFoundException>(() => Mocker.Resolve<InstallUpdateService>().Start(targetFolder))
|
Assert.Throws<DirectoryNotFoundException>(() => Subject.Start(targetFolder))
|
||||||
.Message.Should().StartWith("Update folder doesn't exist");
|
.Message.Should().StartWith("Update folder doesn't exist");
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -85,8 +85,9 @@
|
|||||||
<Reference Include="System.Xml" />
|
<Reference Include="System.Xml" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
<Compile Include="StartNzbDroneService.cs" />
|
||||||
<Compile Include="ProgramFixture.cs" />
|
<Compile Include="ProgramFixture.cs" />
|
||||||
<Compile Include="UpdateProviderVerifyFixture.cs" />
|
<Compile Include="InstallUpdateServiceFixture.cs" />
|
||||||
<Compile Include="UpdateProviderStartFixture.cs" />
|
<Compile Include="UpdateProviderStartFixture.cs" />
|
||||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
40
NzbDrone.Update.Test/StartNzbDroneService.cs
Normal file
40
NzbDrone.Update.Test/StartNzbDroneService.cs
Normal file
@ -0,0 +1,40 @@
|
|||||||
|
using System;
|
||||||
|
using System.IO;
|
||||||
|
using FluentAssertions;
|
||||||
|
using Moq;
|
||||||
|
using NUnit.Framework;
|
||||||
|
using NzbDrone.Common;
|
||||||
|
using NzbDrone.Test.Common;
|
||||||
|
using NzbDrone.Update.UpdateEngine;
|
||||||
|
|
||||||
|
namespace NzbDrone.Update.Test
|
||||||
|
{
|
||||||
|
[TestFixture]
|
||||||
|
public class StartNzbDroneServiceFixture : TestBase<StartNzbDrone>
|
||||||
|
{
|
||||||
|
[Test]
|
||||||
|
public void should_start_service_if_app_type_was_serivce()
|
||||||
|
{
|
||||||
|
string targetFolder = "c:\\NzbDrone\\";
|
||||||
|
|
||||||
|
Subject.Start(AppType.Service, targetFolder);
|
||||||
|
|
||||||
|
Mocker.GetMock<Common.IServiceProvider>().Verify(c => c.Start(ServiceProvider.NZBDRONE_SERVICE_NAME), Times.Once());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void should_start_console_if_app_type_was_serivce_but_start_failed_because_of_permissions()
|
||||||
|
{
|
||||||
|
string targetFolder = "c:\\NzbDrone\\";
|
||||||
|
|
||||||
|
Mocker.GetMock<Common.IServiceProvider>().Setup(c => c.Start(ServiceProvider.NZBDRONE_SERVICE_NAME)).Throws(new InvalidOperationException());
|
||||||
|
|
||||||
|
Subject.Start(AppType.Service, targetFolder);
|
||||||
|
|
||||||
|
Mocker.GetMock<IProcessProvider>().Verify(c => c.Start("c:\\NzbDrone\\NzbDrone.Console.exe"), Times.Once());
|
||||||
|
|
||||||
|
ExceptionVerification.ExpectedWarns(1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -1,6 +1,8 @@
|
|||||||
|
using System;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using NLog;
|
using NLog;
|
||||||
using NzbDrone.Common;
|
using NzbDrone.Common;
|
||||||
|
using IServiceProvider = NzbDrone.Common.IServiceProvider;
|
||||||
|
|
||||||
namespace NzbDrone.Update.UpdateEngine
|
namespace NzbDrone.Update.UpdateEngine
|
||||||
{
|
{
|
||||||
@ -27,19 +29,43 @@ public void Start(AppType appType, string installationFolder)
|
|||||||
_logger.Info("Starting NzbDrone");
|
_logger.Info("Starting NzbDrone");
|
||||||
if (appType == AppType.Service)
|
if (appType == AppType.Service)
|
||||||
{
|
{
|
||||||
_logger.Info("Starting NzbDrone service");
|
try
|
||||||
_serviceProvider.Start(ServiceProvider.NZBDRONE_SERVICE_NAME);
|
{
|
||||||
|
StartService();
|
||||||
|
|
||||||
|
}
|
||||||
|
catch (InvalidOperationException e)
|
||||||
|
{
|
||||||
|
_logger.Warn("Couldn't start NzbDrone Service (Most likely due to permission issues). falling back to console.", e);
|
||||||
|
StartConsole(installationFolder);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else if (appType == AppType.Console)
|
else if (appType == AppType.Console)
|
||||||
{
|
{
|
||||||
_logger.Info("Starting NzbDrone with Console");
|
StartConsole(installationFolder);
|
||||||
_processProvider.Start(Path.Combine(installationFolder, "NzbDrone.Console.exe"));
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
{
|
||||||
|
StartWinform(installationFolder);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void StartService()
|
||||||
|
{
|
||||||
|
_logger.Info("Starting NzbDrone service");
|
||||||
|
_serviceProvider.Start(ServiceProvider.NZBDRONE_SERVICE_NAME);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void StartWinform(string installationFolder)
|
||||||
{
|
{
|
||||||
_logger.Info("Starting NzbDrone without Console");
|
_logger.Info("Starting NzbDrone without Console");
|
||||||
_processProvider.Start(Path.Combine(installationFolder, "NzbDrone.exe"));
|
_processProvider.Start(Path.Combine(installationFolder, "NzbDrone.exe"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void StartConsole(string installationFolder)
|
||||||
|
{
|
||||||
|
_logger.Info("Starting NzbDrone with Console");
|
||||||
|
_processProvider.Start(Path.Combine(installationFolder, "NzbDrone.Console.exe"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user