mirror of
https://github.com/Radarr/Radarr.git
synced 2024-08-18 08:19:38 +02:00
Shutdown working on mono
This commit is contained in:
parent
aa1a76fe72
commit
6ff9c9f61e
@ -269,6 +269,7 @@ public void Kill(int processId)
|
||||
|
||||
if (process.HasExited)
|
||||
{
|
||||
Logger.Trace("Process has already exited");
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -25,6 +25,9 @@ public static void Main(string[] args)
|
||||
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 @@ public Scheduler(ITaskManager taskManager, ICommandExecutor commandExecutor, Log
|
||||
_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 @@ private void ExecuteCommands()
|
||||
}
|
||||
}
|
||||
|
||||
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 @@ public class QueueScheduler : IHandle<ApplicationStartedEvent>,
|
||||
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 @@ public void Handle(ApplicationStartedEvent message)
|
||||
|
||||
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 @@ public class NzbDroneServiceFactory : ServiceBase, INzbDroneServiceFactory, IHan
|
||||
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 @@ public NzbDroneServiceFactory(IConfigFileProvider configFileProvider, IHostContr
|
||||
_priorityMonitor = priorityMonitor;
|
||||
_startupContext = startupContext;
|
||||
_browserService = browserService;
|
||||
_processProvider = processProvider;
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
@ -43,6 +53,11 @@ protected override void OnStart(string[] args)
|
||||
|
||||
public void Start()
|
||||
{
|
||||
if (OsInfo.IsLinux)
|
||||
{
|
||||
Console.CancelKeyPress += (sender, eventArgs) => _processProvider.Kill(_processProvider.GetCurrentProcess().Id);
|
||||
}
|
||||
|
||||
_runtimeInfo.IsRunning = true;
|
||||
_hostController.StartServer();
|
||||
|
||||
@ -75,6 +90,11 @@ private void Shutdown()
|
||||
|
||||
public void Handle(ApplicationShutdownRequested message)
|
||||
{
|
||||
if (OsInfo.IsLinux)
|
||||
{
|
||||
_processProvider.Kill(_processProvider.GetCurrentProcess().Id);
|
||||
}
|
||||
|
||||
if (!_runtimeInfo.IsWindowsService && !message.Restarting)
|
||||
{
|
||||
Shutdown();
|
||||
|
@ -14,7 +14,6 @@ private IPersistentConnectionContext Context
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void Execute(BroadcastSignalRMessage message)
|
||||
{
|
||||
Context.Connection.Broadcast(message.Body);
|
||||
|
Loading…
Reference in New Issue
Block a user