|
|
@ -2,18 +2,19 @@
|
|
|
|
using NLog;
|
|
|
|
using NLog;
|
|
|
|
using NzbDrone.Common.EnvironmentInfo;
|
|
|
|
using NzbDrone.Common.EnvironmentInfo;
|
|
|
|
using NzbDrone.Core.Configuration;
|
|
|
|
using NzbDrone.Core.Configuration;
|
|
|
|
|
|
|
|
using NzbDrone.Core.Lifecycle;
|
|
|
|
|
|
|
|
using NzbDrone.Core.Messaging.Events;
|
|
|
|
using NzbDrone.Host.Owin;
|
|
|
|
using NzbDrone.Host.Owin;
|
|
|
|
|
|
|
|
|
|
|
|
namespace NzbDrone.Host
|
|
|
|
namespace NzbDrone.Host
|
|
|
|
{
|
|
|
|
{
|
|
|
|
public interface INzbDroneServiceFactory
|
|
|
|
public interface INzbDroneServiceFactory
|
|
|
|
{
|
|
|
|
{
|
|
|
|
bool IsServiceStopped { get; }
|
|
|
|
|
|
|
|
ServiceBase Build();
|
|
|
|
ServiceBase Build();
|
|
|
|
void Start();
|
|
|
|
void Start();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public class NzbDroneServiceFactory : ServiceBase, INzbDroneServiceFactory
|
|
|
|
public class NzbDroneServiceFactory : ServiceBase, INzbDroneServiceFactory, IHandle<ApplicationShutdownRequested>
|
|
|
|
{
|
|
|
|
{
|
|
|
|
private readonly IConfigFileProvider _configFileProvider;
|
|
|
|
private readonly IConfigFileProvider _configFileProvider;
|
|
|
|
private readonly IRuntimeInfo _runtimeInfo;
|
|
|
|
private readonly IRuntimeInfo _runtimeInfo;
|
|
|
@ -42,6 +43,7 @@ namespace NzbDrone.Host
|
|
|
|
|
|
|
|
|
|
|
|
public void Start()
|
|
|
|
public void Start()
|
|
|
|
{
|
|
|
|
{
|
|
|
|
|
|
|
|
_runtimeInfo.IsRunning = true;
|
|
|
|
_hostController.StartServer();
|
|
|
|
_hostController.StartServer();
|
|
|
|
|
|
|
|
|
|
|
|
if (!_startupContext.Flags.Contains(StartupContext.NO_BROWSER)
|
|
|
|
if (!_startupContext.Flags.Contains(StartupContext.NO_BROWSER)
|
|
|
@ -54,19 +56,29 @@ namespace NzbDrone.Host
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
protected override void OnStop()
|
|
|
|
protected override void OnStop()
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
Shutdown();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public ServiceBase Build()
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
return this;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private void Shutdown()
|
|
|
|
{
|
|
|
|
{
|
|
|
|
_logger.Info("Attempting to stop application.");
|
|
|
|
_logger.Info("Attempting to stop application.");
|
|
|
|
_hostController.StopServer();
|
|
|
|
_hostController.StopServer();
|
|
|
|
_logger.Info("Application has finished stop routine.");
|
|
|
|
_logger.Info("Application has finished stop routine.");
|
|
|
|
IsServiceStopped = true;
|
|
|
|
_runtimeInfo.IsRunning = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public bool IsServiceStopped { get; private set; }
|
|
|
|
public void Handle(ApplicationShutdownRequested message)
|
|
|
|
|
|
|
|
|
|
|
|
public ServiceBase Build()
|
|
|
|
|
|
|
|
{
|
|
|
|
{
|
|
|
|
return this;
|
|
|
|
if (!_runtimeInfo.IsWindowsService)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
Shutdown();
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|