|
|
@ -1,4 +1,5 @@
|
|
|
|
using NzbDrone.Common;
|
|
|
|
using System.IO;
|
|
|
|
|
|
|
|
using NzbDrone.Common;
|
|
|
|
using NzbDrone.Common.EnvironmentInfo;
|
|
|
|
using NzbDrone.Common.EnvironmentInfo;
|
|
|
|
using NzbDrone.Common.Processes;
|
|
|
|
using NzbDrone.Common.Processes;
|
|
|
|
using NzbDrone.Core.Lifecycle.Commands;
|
|
|
|
using NzbDrone.Core.Lifecycle.Commands;
|
|
|
@ -12,42 +13,66 @@ namespace NzbDrone.Core.Lifecycle
|
|
|
|
{
|
|
|
|
{
|
|
|
|
private readonly IEventAggregator _eventAggregator;
|
|
|
|
private readonly IEventAggregator _eventAggregator;
|
|
|
|
private readonly IRuntimeInfo _runtimeInfo;
|
|
|
|
private readonly IRuntimeInfo _runtimeInfo;
|
|
|
|
|
|
|
|
private readonly IAppFolderInfo _appFolderInfo;
|
|
|
|
private readonly IServiceProvider _serviceProvider;
|
|
|
|
private readonly IServiceProvider _serviceProvider;
|
|
|
|
private readonly IProcessProvider _processProvider;
|
|
|
|
private readonly IProcessProvider _processProvider;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public LifestyleService(IEventAggregator eventAggregator,
|
|
|
|
public LifestyleService(IEventAggregator eventAggregator,
|
|
|
|
IRuntimeInfo runtimeInfo,
|
|
|
|
IRuntimeInfo runtimeInfo,
|
|
|
|
|
|
|
|
IAppFolderInfo appFolderInfo,
|
|
|
|
IServiceProvider serviceProvider,
|
|
|
|
IServiceProvider serviceProvider,
|
|
|
|
IProcessProvider processProvider)
|
|
|
|
IProcessProvider processProvider)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
_eventAggregator = eventAggregator;
|
|
|
|
_eventAggregator = eventAggregator;
|
|
|
|
_runtimeInfo = runtimeInfo;
|
|
|
|
_runtimeInfo = runtimeInfo;
|
|
|
|
|
|
|
|
_appFolderInfo = appFolderInfo;
|
|
|
|
_serviceProvider = serviceProvider;
|
|
|
|
_serviceProvider = serviceProvider;
|
|
|
|
_processProvider = processProvider;
|
|
|
|
_processProvider = processProvider;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void Execute(ShutdownCommand message)
|
|
|
|
public void Execute(ShutdownCommand message)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
|
|
|
|
_eventAggregator.PublishEvent(new ApplicationShutdownRequested());
|
|
|
|
|
|
|
|
|
|
|
|
if (_runtimeInfo.IsWindowsService)
|
|
|
|
if (_runtimeInfo.IsWindowsService)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
_serviceProvider.Stop(ServiceProvider.NZBDRONE_SERVICE_NAME);
|
|
|
|
_serviceProvider.Stop(ServiceProvider.NZBDRONE_SERVICE_NAME);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
else
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
_eventAggregator.PublishEvent(new ApplicationShutdownRequested());
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void Execute(RestartCommand message)
|
|
|
|
public void Execute(RestartCommand message)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
|
|
|
|
_eventAggregator.PublishEvent(new ApplicationShutdownRequested(true));
|
|
|
|
|
|
|
|
|
|
|
|
if (_runtimeInfo.IsWindowsService)
|
|
|
|
if (_runtimeInfo.IsWindowsService)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
_serviceProvider.Restart(ServiceProvider.NZBDRONE_SERVICE_NAME);
|
|
|
|
_serviceProvider.Restart(ServiceProvider.NZBDRONE_SERVICE_NAME);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
_eventAggregator.PublishEvent(new ApplicationRestartRequested());
|
|
|
|
else
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
//TODO: move this to environment specific projects
|
|
|
|
|
|
|
|
if (OsInfo.IsWindows)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
if (_runtimeInfo.IsConsole)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
//Run console with switch
|
|
|
|
|
|
|
|
var path = Path.Combine(_appFolderInfo.StartUpFolder,
|
|
|
|
|
|
|
|
ProcessProvider.NZB_DRONE_CONSOLE_PROCESS_NAME + ".exe");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
_processProvider.SpawnNewProcess(path, "--terminateexisting --nobrowser");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
else
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
var path = Path.Combine(_appFolderInfo.StartUpFolder,
|
|
|
|
|
|
|
|
ProcessProvider.NZB_DRONE_PROCESS_NAME + ".exe");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
_processProvider.Start(path, "--terminateexisting --nobrowser");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|