mirror of
https://github.com/Sonarr/Sonarr.git
synced 2024-12-14 11:23:42 +02:00
fixed NzbDrone using 100% cpu when console not available.
This commit is contained in:
parent
e377e02db4
commit
75a46a3abe
@ -50,11 +50,9 @@ public void Route_should_call_uninstall_service_when_application_mode_is_uninsta
|
||||
public void Route_should_call_console_service_when_application_mode_is_console()
|
||||
{
|
||||
Mocker.GetMock<IRuntimeInfo>().SetupGet(c => c.IsUserInteractive).Returns(true);
|
||||
Mocker.GetMock<IConsoleService>().SetupGet(c => c.IsConsoleApplication).Returns(true);
|
||||
|
||||
Subject.Route(ApplicationModes.Interactive);
|
||||
|
||||
Mocker.GetMock<IConsoleService>().Verify(c => c.WaitForClose(), Times.Once());
|
||||
Mocker.GetMock<INzbDroneServiceFactory>().Verify(c => c.Start(), Times.Once());
|
||||
}
|
||||
|
||||
|
@ -7,8 +7,6 @@ namespace NzbDrone.Common
|
||||
{
|
||||
public interface IConsoleService
|
||||
{
|
||||
bool IsConsoleApplication { get; }
|
||||
void WaitForClose();
|
||||
void PrintHelp();
|
||||
void PrintServiceAlreadyExist();
|
||||
void PrintServiceDoesNotExist();
|
||||
@ -16,26 +14,18 @@ public interface IConsoleService
|
||||
|
||||
public class ConsoleService : IConsoleService
|
||||
{
|
||||
public bool IsConsoleApplication
|
||||
public static bool IsConsoleAvailable
|
||||
{
|
||||
get { return Console.In != StreamReader.Null; }
|
||||
}
|
||||
|
||||
public void WaitForClose()
|
||||
{
|
||||
while (true)
|
||||
{
|
||||
Console.ReadLine();
|
||||
}
|
||||
}
|
||||
|
||||
public void PrintHelp()
|
||||
{
|
||||
Console.WriteLine();
|
||||
Console.WriteLine(" Usage: {0} <command> ", Process.GetCurrentProcess().MainModule.ModuleName);
|
||||
Console.WriteLine(" Commands:");
|
||||
Console.WriteLine(" /{0} Install the application as a Windows Service ({1}).",StartupArguments.INSTALL_SERVICE, ServiceProvider.NZBDRONE_SERVICE_NAME);
|
||||
Console.WriteLine(" /{0} Uninstall already installed Windows Service ({1}).",StartupArguments.UNINSTALL_SERVICE, ServiceProvider.NZBDRONE_SERVICE_NAME);
|
||||
Console.WriteLine(" /{0} Install the application as a Windows Service ({1}).", StartupArguments.INSTALL_SERVICE, ServiceProvider.NZBDRONE_SERVICE_NAME);
|
||||
Console.WriteLine(" /{0} Uninstall already installed Windows Service ({1}).", StartupArguments.UNINSTALL_SERVICE, ServiceProvider.NZBDRONE_SERVICE_NAME);
|
||||
Console.WriteLine(" /{0} Don't open NzbDrone in a browser", StartupArguments.NO_BROWSER);
|
||||
Console.WriteLine(" <No Arguments> Run application in console mode.");
|
||||
}
|
||||
|
@ -21,6 +21,7 @@ public interface IProcessProvider
|
||||
bool Exists(string processName);
|
||||
ProcessPriorityClass GetCurrentProcessPriority();
|
||||
Process Start(string path, string args = null, Action<string> onOutputDataReceived = null, Action<string> onErrorDataReceived = null);
|
||||
Process SpawnNewProcess(string path, string args = null);
|
||||
}
|
||||
|
||||
public class ProcessProvider : IProcessProvider
|
||||
@ -86,6 +87,8 @@ public void OpenDefaultBrowser(string url)
|
||||
process.Start();
|
||||
}
|
||||
|
||||
|
||||
|
||||
public Process Start(string path, string args = null, Action<string> onOutputDataReceived = null, Action<string> onErrorDataReceived = null)
|
||||
{
|
||||
|
||||
@ -147,6 +150,27 @@ public Process Start(string path, string args = null, Action<string> onOutputDat
|
||||
return process;
|
||||
}
|
||||
|
||||
public Process SpawnNewProcess(string path, string args = null)
|
||||
{
|
||||
if (OsInfo.IsMono && path.EndsWith(".exe", StringComparison.InvariantCultureIgnoreCase))
|
||||
{
|
||||
args = path + " " + args;
|
||||
path = "mono";
|
||||
}
|
||||
|
||||
Logger.Info("Starting {0} {1}", path, args);
|
||||
|
||||
var startInfo = new ProcessStartInfo(path, args);
|
||||
var process = new Process
|
||||
{
|
||||
StartInfo = startInfo
|
||||
};
|
||||
|
||||
process.Start();
|
||||
|
||||
return process;
|
||||
}
|
||||
|
||||
public void WaitForExit(Process process)
|
||||
{
|
||||
Logger.Trace("Waiting for process {0} to exit.", process.ProcessName);
|
||||
|
@ -1,4 +1,5 @@
|
||||
using System;
|
||||
using NzbDrone.Common;
|
||||
using NzbDrone.Common.EnvironmentInfo;
|
||||
using NzbDrone.Host;
|
||||
|
||||
@ -12,15 +13,19 @@ public static void Main(string[] args)
|
||||
{
|
||||
Bootstrap.Start(new StartupArguments(args), new ConsoleAlerts());
|
||||
}
|
||||
catch (TerminateApplicationException)
|
||||
catch (TerminateApplicationException)
|
||||
{
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
System.Console.WriteLine(e.ToString());
|
||||
}
|
||||
System.Console.WriteLine("Press enter to exit...");
|
||||
System.Console.ReadLine();
|
||||
|
||||
if (ConsoleService.IsConsoleAvailable)
|
||||
{
|
||||
System.Console.WriteLine("Press enter to exit...");
|
||||
System.Console.ReadLine();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -133,7 +133,6 @@
|
||||
<Compile Include="MediaFileTests\EpisodeImportTests\FreeSpaceSpecificationFixture.cs" />
|
||||
<Compile Include="MediaFileTests\RenameEpisodeFileServiceFixture.cs" />
|
||||
<Compile Include="MediaFileTests\UpgradeMediaFileServiceFixture.cs" />
|
||||
<Compile Include="MediaFileTests\EpisodeImportTests\NotExistingFileSpecificationFixture.cs" />
|
||||
<Compile Include="MediaFileTests\ImportApprovedEpisodesFixture.cs" />
|
||||
<Compile Include="MediaFileTests\EpisodeImportTests\UpgradeSpecificationFixture.cs" />
|
||||
<Compile Include="MediaFileTests\EpisodeImportTests\NotSampleSpecificationFixture.cs" />
|
||||
|
@ -227,7 +227,6 @@
|
||||
<Compile Include="MediaFiles\EpisodeImport\ImportApprovedEpisodes.cs" />
|
||||
<Compile Include="MediaFiles\EpisodeImport\Specifications\NotInUseSpecification.cs" />
|
||||
<Compile Include="MediaFiles\EpisodeImport\Specifications\FreeSpaceSpecification.cs" />
|
||||
<Compile Include="MediaFiles\EpisodeImport\Specifications\NotExistingFileSpecification.cs" />
|
||||
<Compile Include="MediaFiles\EpisodeImport\Specifications\UpgradeSpecification.cs" />
|
||||
<Compile Include="MediaFiles\EpisodeImport\Specifications\NotSampleSpecification.cs" />
|
||||
<Compile Include="MediaFiles\Events\EpisodeImportedEvent.cs" />
|
||||
|
@ -48,11 +48,6 @@ public void Route(ApplicationModes applicationModes)
|
||||
{
|
||||
_logger.Trace("Console selected");
|
||||
_nzbDroneServiceFactory.Start();
|
||||
if (_consoleService.IsConsoleApplication)
|
||||
{
|
||||
_consoleService.WaitForClose();
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
case ApplicationModes.InstallService:
|
||||
|
@ -15,16 +15,15 @@ public class StartNzbDroneServiceFixture : TestBase<StartNzbDrone>
|
||||
[Test]
|
||||
public void should_start_service_if_app_type_was_serivce()
|
||||
{
|
||||
string targetFolder = "c:\\NzbDrone\\";
|
||||
const string targetFolder = "c:\\NzbDrone\\";
|
||||
|
||||
Subject.Start(AppType.Service, targetFolder);
|
||||
|
||||
Mocker.GetMock<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()
|
||||
public void should_start_console_if_app_type_was_service_but_start_failed_because_of_permissions()
|
||||
{
|
||||
const string targetFolder = "c:\\NzbDrone\\";
|
||||
|
||||
@ -32,7 +31,7 @@ public void should_start_console_if_app_type_was_serivce_but_start_failed_becaus
|
||||
|
||||
Subject.Start(AppType.Service, targetFolder);
|
||||
|
||||
Mocker.GetMock<IProcessProvider>().Verify(c => c.Start("c:\\NzbDrone\\NzbDrone.Console.exe", StartupArguments.NO_BROWSER, null, null), Times.Once());
|
||||
Mocker.GetMock<IProcessProvider>().Verify(c => c.SpawnNewProcess("c:\\NzbDrone\\NzbDrone.Console.exe", StartupArguments.NO_BROWSER), Times.Once());
|
||||
|
||||
ExceptionVerification.ExpectedWarns(1);
|
||||
}
|
||||
|
@ -1,5 +1,4 @@
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
using NLog;
|
||||
using NzbDrone.Common;
|
||||
@ -73,7 +72,7 @@ private void Start(string installationFolder, string fileName)
|
||||
_logger.Info("Starting {0}", fileName);
|
||||
var path = Path.Combine(installationFolder, fileName);
|
||||
|
||||
_processProvider.Start(path, StartupArguments.NO_BROWSER);
|
||||
_processProvider.SpawnNewProcess(path, StartupArguments.NO_BROWSER);
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user