Shutdown working on mono

pull/4/head
markus101 11 years ago committed by Mark McDowall
parent aa1a76fe72
commit 6ff9c9f61e

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

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

@ -27,16 +27,6 @@ namespace NzbDrone.Core.Jobs
_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()
{
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)
{
_logger.Info("Shutting down scheduler");
_cancellationTokenSource.Cancel(true);
Timer.Stop();
}

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

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

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

Loading…
Cancel
Save