mirror of
https://github.com/lidarr/lidarr.git
synced 2025-08-23 14:55:20 -07:00
parent
c34137c423
commit
fa212872ab
4 changed files with 74 additions and 1 deletions
|
@ -26,6 +26,7 @@ namespace Radarr.Host
|
||||||
private readonly IBrowserService _browserService;
|
private readonly IBrowserService _browserService;
|
||||||
private readonly IContainer _container;
|
private readonly IContainer _container;
|
||||||
private readonly Logger _logger;
|
private readonly Logger _logger;
|
||||||
|
private CancelHandler _cancelHandler;
|
||||||
|
|
||||||
public NzbDroneServiceFactory(IConfigFileProvider configFileProvider,
|
public NzbDroneServiceFactory(IConfigFileProvider configFileProvider,
|
||||||
IHostController hostController,
|
IHostController hostController,
|
||||||
|
@ -53,7 +54,8 @@ namespace Radarr.Host
|
||||||
{
|
{
|
||||||
if (OsInfo.IsNotWindows)
|
if (OsInfo.IsNotWindows)
|
||||||
{
|
{
|
||||||
Console.CancelKeyPress += (sender, eventArgs) => LogManager.Configuration = null;
|
//Console.CancelKeyPress += (sender, eventArgs) => eventArgs.Cancel = true;
|
||||||
|
//_cancelHandler = new CancelHandler();
|
||||||
}
|
}
|
||||||
|
|
||||||
_runtimeInfo.IsRunning = true;
|
_runtimeInfo.IsRunning = true;
|
||||||
|
@ -66,6 +68,7 @@ namespace Radarr.Host
|
||||||
_browserService.LaunchWebUI();
|
_browserService.LaunchWebUI();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
_container.Resolve<IEventAggregator>().PublishEvent(new ApplicationStartedEvent());
|
_container.Resolve<IEventAggregator>().PublishEvent(new ApplicationStartedEvent());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -37,6 +37,8 @@ namespace Radarr.Host
|
||||||
var appMode = GetApplicationMode(startupContext);
|
var appMode = GetApplicationMode(startupContext);
|
||||||
|
|
||||||
Start(appMode, startupContext);
|
Start(appMode, startupContext);
|
||||||
|
|
||||||
|
_container.Resolve<ICancelHandler>().Attach();
|
||||||
|
|
||||||
if (startCallback != null)
|
if (startCallback != null)
|
||||||
{
|
{
|
||||||
|
|
67
src/NzbDrone.Host/CancelHandler.cs
Normal file
67
src/NzbDrone.Host/CancelHandler.cs
Normal file
|
@ -0,0 +1,67 @@
|
||||||
|
using System;
|
||||||
|
using NLog;
|
||||||
|
using NzbDrone.Core.Lifecycle;
|
||||||
|
|
||||||
|
namespace Radarr.Host
|
||||||
|
{
|
||||||
|
public interface ICancelHandler
|
||||||
|
{
|
||||||
|
void Attach();
|
||||||
|
}
|
||||||
|
|
||||||
|
class CancelHandler : ICancelHandler
|
||||||
|
{
|
||||||
|
private object _syncRoot;
|
||||||
|
private volatile bool _cancelInitiated;
|
||||||
|
private readonly ILifecycleService _lifecycleService;
|
||||||
|
|
||||||
|
public CancelHandler(ILifecycleService lifecycleService)
|
||||||
|
{
|
||||||
|
_lifecycleService = lifecycleService;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Attach()
|
||||||
|
{
|
||||||
|
Console.CancelKeyPress += HandlerCancelKeyPress;
|
||||||
|
_syncRoot = new object();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void HandlerCancelKeyPress(object sender, ConsoleCancelEventArgs e)
|
||||||
|
{
|
||||||
|
// Tell system to ignore the Ctrl+C and not terminate. We'll do that.
|
||||||
|
e.Cancel = true;
|
||||||
|
|
||||||
|
var shouldTerminate = false;
|
||||||
|
lock (_syncRoot)
|
||||||
|
{
|
||||||
|
shouldTerminate = _cancelInitiated;
|
||||||
|
_cancelInitiated = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: Probably should schedule these on the threadpool.
|
||||||
|
if (shouldTerminate)
|
||||||
|
{
|
||||||
|
UngracefulShutdown();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
GracefulShutdown();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void GracefulShutdown()
|
||||||
|
{
|
||||||
|
Console.WriteLine("Shutdown requested, press Ctrl+C again to terminate directly.");
|
||||||
|
// TODO: Sent ApplicationShutdownRequested event or something like it.
|
||||||
|
_lifecycleService.Shutdown();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void UngracefulShutdown()
|
||||||
|
{
|
||||||
|
Console.WriteLine("Termination requested.");
|
||||||
|
// TODO: Kill it. Shutdown NLog and invoke Environment.Exit.
|
||||||
|
LogManager.Configuration = null;
|
||||||
|
Environment.Exit(0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -113,6 +113,7 @@
|
||||||
</Compile>
|
</Compile>
|
||||||
<Compile Include="Bootstrap.cs" />
|
<Compile Include="Bootstrap.cs" />
|
||||||
<Compile Include="BrowserService.cs" />
|
<Compile Include="BrowserService.cs" />
|
||||||
|
<Compile Include="CancelHandler.cs" />
|
||||||
<Compile Include="IUserAlert.cs" />
|
<Compile Include="IUserAlert.cs" />
|
||||||
<Compile Include="MainAppContainerBuilder.cs" />
|
<Compile Include="MainAppContainerBuilder.cs" />
|
||||||
<Compile Include="Owin\IHostController.cs" />
|
<Compile Include="Owin\IHostController.cs" />
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue