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