When restarting after update if service start fails update app will fallback to console.

pull/3113/head
kay.one 12 years ago
parent 44ff12eaaa
commit d0d95602c6

@ -9,10 +9,8 @@ using NzbDrone.Update.UpdateEngine;
namespace NzbDrone.Update.Test
{
[TestFixture]
public class UpdateProviderVerifyFixture : TestBase
public class InstallUpdateServiceFixture : TestBase<InstallUpdateService>
{
[SetUp]
public void Setup()
{
@ -25,7 +23,7 @@ namespace NzbDrone.Update.Test
[TestCase(" ")]
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");
}
@ -34,7 +32,7 @@ namespace NzbDrone.Update.Test
{
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");
}
@ -52,7 +50,7 @@ namespace NzbDrone.Update.Test
.Setup(c => c.FolderExists(sandboxFolder))
.Returns(false);
Assert.Throws<DirectoryNotFoundException>(() => Mocker.Resolve<InstallUpdateService>().Start(targetFolder))
Assert.Throws<DirectoryNotFoundException>(() => Subject.Start(targetFolder))
.Message.Should().StartWith("Update folder doesn't exist");
}
}

@ -85,8 +85,9 @@
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="StartNzbDroneService.cs" />
<Compile Include="ProgramFixture.cs" />
<Compile Include="UpdateProviderVerifyFixture.cs" />
<Compile Include="InstallUpdateServiceFixture.cs" />
<Compile Include="UpdateProviderStartFixture.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>

@ -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 NLog;
using NzbDrone.Common;
using IServiceProvider = NzbDrone.Common.IServiceProvider;
namespace NzbDrone.Update.UpdateEngine
{
@ -27,19 +29,43 @@ namespace NzbDrone.Update.UpdateEngine
_logger.Info("Starting NzbDrone");
if (appType == AppType.Service)
{
_logger.Info("Starting NzbDrone service");
_serviceProvider.Start(ServiceProvider.NZBDRONE_SERVICE_NAME);
try
{
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)
{
_logger.Info("Starting NzbDrone with Console");
_processProvider.Start(Path.Combine(installationFolder, "NzbDrone.Console.exe"));
StartConsole(installationFolder);
}
else
{
_logger.Info("Starting NzbDrone without Console");
_processProvider.Start(Path.Combine(installationFolder, "NzbDrone.exe"));
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");
_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…
Cancel
Save