2013-05-21 04:03:05 +00:00
|
|
|
using System;
|
|
|
|
using NLog;
|
|
|
|
using NzbDrone.Common;
|
2013-09-20 23:56:17 +00:00
|
|
|
using NzbDrone.Common.Processes;
|
2013-05-21 04:03:05 +00:00
|
|
|
using IServiceProvider = NzbDrone.Common.IServiceProvider;
|
|
|
|
|
|
|
|
namespace NzbDrone.Update.UpdateEngine
|
|
|
|
{
|
|
|
|
public interface ITerminateNzbDrone
|
|
|
|
{
|
|
|
|
void Terminate();
|
|
|
|
}
|
|
|
|
|
|
|
|
public class TerminateNzbDrone : ITerminateNzbDrone
|
|
|
|
{
|
|
|
|
private readonly IServiceProvider _serviceProvider;
|
|
|
|
private readonly IProcessProvider _processProvider;
|
|
|
|
private readonly Logger _logger;
|
|
|
|
|
|
|
|
public TerminateNzbDrone(IServiceProvider serviceProvider, IProcessProvider processProvider, Logger logger)
|
|
|
|
{
|
|
|
|
_serviceProvider = serviceProvider;
|
|
|
|
_processProvider = processProvider;
|
|
|
|
_logger = logger;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void Terminate()
|
|
|
|
{
|
|
|
|
_logger.Info("Stopping all running services");
|
|
|
|
|
|
|
|
if (_serviceProvider.ServiceExist(ServiceProvider.NZBDRONE_SERVICE_NAME)
|
|
|
|
&& _serviceProvider.IsServiceRunning(ServiceProvider.NZBDRONE_SERVICE_NAME))
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
2013-07-05 18:51:38 +00:00
|
|
|
_logger.Info("NzbDrone Service is installed and running");
|
2013-05-21 04:03:05 +00:00
|
|
|
_serviceProvider.Stop(ServiceProvider.NZBDRONE_SERVICE_NAME);
|
|
|
|
|
|
|
|
}
|
2013-07-05 18:51:38 +00:00
|
|
|
catch (Exception e)
|
2013-05-21 04:03:05 +00:00
|
|
|
{
|
2013-07-05 18:51:38 +00:00
|
|
|
_logger.ErrorException("couldn't stop service", e);
|
2013-05-21 04:03:05 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
_logger.Info("Killing all running processes");
|
|
|
|
|
2013-08-14 05:20:24 +00:00
|
|
|
_processProvider.KillAll(ProcessProvider.NZB_DRONE_CONSOLE_PROCESS_NAME);
|
|
|
|
_processProvider.KillAll(ProcessProvider.NZB_DRONE_PROCESS_NAME);
|
2013-05-21 04:03:05 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|