Shutdown working on mono

This commit is contained in:
markus101 2014-02-03 23:11:36 -08:00 committed by Mark McDowall
parent aa1a76fe72
commit 6ff9c9f61e
6 changed files with 43 additions and 15 deletions

View File

@ -269,6 +269,7 @@ namespace NzbDrone.Common.Processes
if (process.HasExited) if (process.HasExited)
{ {
Logger.Trace("Process has already exited");
return; return;
} }

View File

@ -25,6 +25,9 @@ namespace NzbDrone.Console
Logger.FatalException("EPIC FAIL!", e); Logger.FatalException("EPIC FAIL!", e);
System.Console.WriteLine("Press any key to exit..."); System.Console.WriteLine("Press any key to exit...");
System.Console.ReadLine(); System.Console.ReadLine();
//Need this to terminate on mono (thanks nlog)
LogManager.Configuration = null;
} }
} }
} }

View File

@ -27,16 +27,6 @@ namespace NzbDrone.Core.Jobs
_logger = logger; _logger = logger;
} }
public void Handle(ApplicationStartedEvent message)
{
_cancellationTokenSource = new CancellationTokenSource();
Timer.Interval = 1000 * 30;
Timer.Elapsed += (o, args) => Task.Factory.StartNew(ExecuteCommands, _cancellationTokenSource.Token)
.LogExceptions();
Timer.Start();
}
private void ExecuteCommands() private void ExecuteCommands()
{ {
try try
@ -70,8 +60,19 @@ namespace NzbDrone.Core.Jobs
} }
} }
public void Handle(ApplicationStartedEvent message)
{
_cancellationTokenSource = new CancellationTokenSource();
Timer.Interval = 1000 * 30;
Timer.Elapsed += (o, args) => Task.Factory.StartNew(ExecuteCommands, _cancellationTokenSource.Token)
.LogExceptions();
Timer.Start();
}
public void Handle(ApplicationShutdownRequested message) public void Handle(ApplicationShutdownRequested message)
{ {
_logger.Info("Shutting down scheduler");
_cancellationTokenSource.Cancel(true); _cancellationTokenSource.Cancel(true);
Timer.Stop(); Timer.Stop();
} }

View File

@ -1,5 +1,6 @@
using System.Threading; using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
using NLog;
using NzbDrone.Common.TPL; using NzbDrone.Common.TPL;
using NzbDrone.Core.Lifecycle; using NzbDrone.Core.Lifecycle;
using NzbDrone.Core.Messaging.Events; using NzbDrone.Core.Messaging.Events;
@ -11,12 +12,14 @@ namespace NzbDrone.Core.Queue
IHandle<ApplicationShutdownRequested> IHandle<ApplicationShutdownRequested>
{ {
private readonly IEventAggregator _eventAggregator; private readonly IEventAggregator _eventAggregator;
private readonly Logger _logger;
private static readonly Timer Timer = new Timer(); private static readonly Timer Timer = new Timer();
private static CancellationTokenSource _cancellationTokenSource; private static CancellationTokenSource _cancellationTokenSource;
public QueueScheduler(IEventAggregator eventAggregator) public QueueScheduler(IEventAggregator eventAggregator, Logger logger)
{ {
_eventAggregator = eventAggregator; _eventAggregator = eventAggregator;
_logger = logger;
} }
private void CheckQueue() private void CheckQueue()
@ -47,6 +50,7 @@ namespace NzbDrone.Core.Queue
public void Handle(ApplicationShutdownRequested message) public void Handle(ApplicationShutdownRequested message)
{ {
_logger.Info("Shutting down queue scheduler");
_cancellationTokenSource.Cancel(true); _cancellationTokenSource.Cancel(true);
Timer.Stop(); Timer.Stop();
} }

View File

@ -1,6 +1,8 @@
using System.ServiceProcess; using System;
using System.ServiceProcess;
using NLog; using NLog;
using NzbDrone.Common.EnvironmentInfo; using NzbDrone.Common.EnvironmentInfo;
using NzbDrone.Common.Processes;
using NzbDrone.Core.Configuration; using NzbDrone.Core.Configuration;
using NzbDrone.Core.Lifecycle; using NzbDrone.Core.Lifecycle;
using NzbDrone.Core.Messaging.Events; using NzbDrone.Core.Messaging.Events;
@ -22,10 +24,17 @@ namespace NzbDrone.Host
private readonly PriorityMonitor _priorityMonitor; private readonly PriorityMonitor _priorityMonitor;
private readonly IStartupContext _startupContext; private readonly IStartupContext _startupContext;
private readonly IBrowserService _browserService; private readonly IBrowserService _browserService;
private readonly IProcessProvider _processProvider;
private readonly Logger _logger; private readonly Logger _logger;
public NzbDroneServiceFactory(IConfigFileProvider configFileProvider, IHostController hostController, public NzbDroneServiceFactory(IConfigFileProvider configFileProvider,
IRuntimeInfo runtimeInfo, PriorityMonitor priorityMonitor, IStartupContext startupContext, IBrowserService browserService, Logger logger) IHostController hostController,
IRuntimeInfo runtimeInfo,
PriorityMonitor priorityMonitor,
IStartupContext startupContext,
IBrowserService browserService,
IProcessProvider processProvider,
Logger logger)
{ {
_configFileProvider = configFileProvider; _configFileProvider = configFileProvider;
_hostController = hostController; _hostController = hostController;
@ -33,6 +42,7 @@ namespace NzbDrone.Host
_priorityMonitor = priorityMonitor; _priorityMonitor = priorityMonitor;
_startupContext = startupContext; _startupContext = startupContext;
_browserService = browserService; _browserService = browserService;
_processProvider = processProvider;
_logger = logger; _logger = logger;
} }
@ -43,6 +53,11 @@ namespace NzbDrone.Host
public void Start() public void Start()
{ {
if (OsInfo.IsLinux)
{
Console.CancelKeyPress += (sender, eventArgs) => _processProvider.Kill(_processProvider.GetCurrentProcess().Id);
}
_runtimeInfo.IsRunning = true; _runtimeInfo.IsRunning = true;
_hostController.StartServer(); _hostController.StartServer();
@ -75,6 +90,11 @@ namespace NzbDrone.Host
public void Handle(ApplicationShutdownRequested message) public void Handle(ApplicationShutdownRequested message)
{ {
if (OsInfo.IsLinux)
{
_processProvider.Kill(_processProvider.GetCurrentProcess().Id);
}
if (!_runtimeInfo.IsWindowsService && !message.Restarting) if (!_runtimeInfo.IsWindowsService && !message.Restarting)
{ {
Shutdown(); Shutdown();

View File

@ -14,7 +14,6 @@ namespace NzbDrone.SignalR
} }
} }
public void Execute(BroadcastSignalRMessage message) public void Execute(BroadcastSignalRMessage message)
{ {
Context.Connection.Broadcast(message.Body); Context.Connection.Broadcast(message.Body);