2013-01-06 08:11:14 +00:00
|
|
|
|
using System;
|
|
|
|
|
using NLog;
|
|
|
|
|
using NzbDrone.Common;
|
2013-02-18 07:59:43 +00:00
|
|
|
|
using NzbDrone.Core.Jobs;
|
2013-01-06 08:11:14 +00:00
|
|
|
|
using NzbDrone.Core.Model.Notification;
|
|
|
|
|
|
2013-02-18 07:59:43 +00:00
|
|
|
|
namespace NzbDrone.Core.Lifecycle
|
2013-01-06 08:11:14 +00:00
|
|
|
|
{
|
|
|
|
|
public class AppShutdownJob : IJob
|
|
|
|
|
{
|
|
|
|
|
private readonly ProcessProvider _processProvider;
|
|
|
|
|
private readonly ServiceProvider _serviceProvider;
|
2013-03-30 21:29:02 +00:00
|
|
|
|
private readonly Logger _logger;
|
2013-01-06 08:11:14 +00:00
|
|
|
|
|
|
|
|
|
|
2013-03-30 21:29:02 +00:00
|
|
|
|
public AppShutdownJob(ProcessProvider processProvider, ServiceProvider serviceProvider, Logger logger)
|
2013-01-06 08:11:14 +00:00
|
|
|
|
{
|
|
|
|
|
_processProvider = processProvider;
|
|
|
|
|
_serviceProvider = serviceProvider;
|
2013-03-30 21:29:02 +00:00
|
|
|
|
_logger = logger;
|
2013-01-06 08:11:14 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public string Name
|
|
|
|
|
{
|
|
|
|
|
get { return "Shutdown NzbDrone"; }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public TimeSpan DefaultInterval
|
|
|
|
|
{
|
|
|
|
|
get { return TimeSpan.FromTicks(0); }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public virtual void Start(ProgressNotification notification, dynamic options)
|
|
|
|
|
{
|
|
|
|
|
notification.CurrentMessage = "Shutting down NzbDrone";
|
2013-03-30 21:29:02 +00:00
|
|
|
|
_logger.Info("Shutting down NzbDrone");
|
2013-01-06 08:11:14 +00:00
|
|
|
|
|
|
|
|
|
if (_serviceProvider.ServiceExist(ServiceProvider.NZBDRONE_SERVICE_NAME)
|
|
|
|
|
&& _serviceProvider.IsServiceRunning(ServiceProvider.NZBDRONE_SERVICE_NAME))
|
|
|
|
|
{
|
2013-03-30 21:29:02 +00:00
|
|
|
|
_logger.Debug("Stopping NzbDrone Service");
|
2013-01-06 08:11:14 +00:00
|
|
|
|
_serviceProvider.Stop(ServiceProvider.NZBDRONE_SERVICE_NAME);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
else
|
|
|
|
|
{
|
2013-03-30 21:29:02 +00:00
|
|
|
|
_logger.Debug("Stopping NzbDrone console");
|
2013-01-06 08:11:14 +00:00
|
|
|
|
|
2013-03-30 21:29:02 +00:00
|
|
|
|
var currentProcess = _processProvider.GetCurrentProcess();
|
|
|
|
|
_processProvider.Kill(currentProcess.Id);
|
2013-01-06 08:11:14 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|