|
|
@ -1,4 +1,7 @@
|
|
|
|
using System.Reflection;
|
|
|
|
using System;
|
|
|
|
|
|
|
|
using System.Reflection;
|
|
|
|
|
|
|
|
using System.Threading;
|
|
|
|
|
|
|
|
using NLog;
|
|
|
|
using NzbDrone.Common.Composition;
|
|
|
|
using NzbDrone.Common.Composition;
|
|
|
|
using NzbDrone.Common.EnvironmentInfo;
|
|
|
|
using NzbDrone.Common.EnvironmentInfo;
|
|
|
|
using NzbDrone.Common.Instrumentation;
|
|
|
|
using NzbDrone.Common.Instrumentation;
|
|
|
@ -7,18 +10,21 @@ using NzbDrone.Core.Datastore;
|
|
|
|
|
|
|
|
|
|
|
|
namespace NzbDrone.Host
|
|
|
|
namespace NzbDrone.Host
|
|
|
|
{
|
|
|
|
{
|
|
|
|
public class Bootstrap
|
|
|
|
public static class Bootstrap
|
|
|
|
{
|
|
|
|
{
|
|
|
|
public IContainer Container { get; private set; }
|
|
|
|
private static IContainer _container;
|
|
|
|
|
|
|
|
private static readonly Logger Logger = NzbDroneLogger.GetLogger();
|
|
|
|
|
|
|
|
|
|
|
|
public Bootstrap(StartupArguments args, IUserAlert userAlert)
|
|
|
|
|
|
|
|
|
|
|
|
public static void Start(StartupContext startupContext, IUserAlert userAlert, Action<IContainer> startCallback = null)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
try
|
|
|
|
{
|
|
|
|
{
|
|
|
|
var logger = NzbDroneLogger.GetLogger();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
GlobalExceptionHandlers.Register();
|
|
|
|
GlobalExceptionHandlers.Register();
|
|
|
|
IgnoreCertErrorPolicy.Register();
|
|
|
|
IgnoreCertErrorPolicy.Register();
|
|
|
|
|
|
|
|
|
|
|
|
logger.Info("Starting NzbDrone Console. Version {0}", Assembly.GetExecutingAssembly().GetName().Version);
|
|
|
|
Logger.Info("Starting NzbDrone Console. Version {0}", Assembly.GetExecutingAssembly().GetName().Version);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (!PlatformValidation.IsValidate(userAlert))
|
|
|
|
if (!PlatformValidation.IsValidate(userAlert))
|
|
|
@ -26,21 +32,101 @@ namespace NzbDrone.Host
|
|
|
|
throw new TerminateApplicationException("Missing system requirements");
|
|
|
|
throw new TerminateApplicationException("Missing system requirements");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Container = MainAppContainerBuilder.BuildContainer(args);
|
|
|
|
_container = MainAppContainerBuilder.BuildContainer(startupContext);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var appMode = GetApplicationMode(startupContext);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Start(appMode);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (startCallback != null)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
startCallback(_container);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void Start()
|
|
|
|
SpinToExit(appMode);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
catch (TerminateApplicationException e)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
DbFactory.RegisterDatabase(Container);
|
|
|
|
Logger.Info("Application has been terminated. Reason " + e.Reason);
|
|
|
|
Container.Resolve<Router>().Route();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public void EnsureSingleInstance()
|
|
|
|
private static void Start(ApplicationModes applicationModes)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
if (!IsInUtilityMode(applicationModes))
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
EnsureSingleInstance();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
DbFactory.RegisterDatabase(_container);
|
|
|
|
|
|
|
|
_container.Resolve<Router>().Route(applicationModes);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private static void SpinToExit(ApplicationModes applicationModes)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
if (IsInUtilityMode(applicationModes))
|
|
|
|
{
|
|
|
|
{
|
|
|
|
Container.Resolve<ISingleInstancePolicy>().EnforceSingleInstance();
|
|
|
|
return;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var serviceFactory = _container.Resolve<INzbDroneServiceFactory>();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
while (!serviceFactory.IsServiceStopped)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
Thread.Sleep(1000);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private static void EnsureSingleInstance()
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
_container.Resolve<ISingleInstancePolicy>().EnforceSingleInstance();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private static ApplicationModes GetApplicationMode(StartupContext startupContext)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
if (startupContext.Flags.Contains(StartupContext.HELP))
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
return ApplicationModes.Help;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (!OsInfo.IsLinux && startupContext.InstallService)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
return ApplicationModes.InstallService;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (!OsInfo.IsLinux && startupContext.UninstallService)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
return ApplicationModes.UninstallService;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (_container.Resolve<IRuntimeInfo>().IsWindowsService)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
return ApplicationModes.Service;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return ApplicationModes.Interactive;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private static bool IsInUtilityMode(ApplicationModes applicationMode)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
switch (applicationMode)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
case ApplicationModes.InstallService:
|
|
|
|
|
|
|
|
case ApplicationModes.UninstallService:
|
|
|
|
|
|
|
|
case ApplicationModes.Help:
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|