diff --git a/NzbDrone.App.Test/RouterTest.cs b/NzbDrone.App.Test/RouterTest.cs index b09080571..9232f7784 100644 --- a/NzbDrone.App.Test/RouterTest.cs +++ b/NzbDrone.App.Test/RouterTest.cs @@ -62,7 +62,7 @@ namespace NzbDrone.App.Test [TestCase(ApplicationModes.InstallService)] [TestCase(ApplicationModes.UninstallService)] [TestCase(ApplicationModes.Help)] - public void Route_should_call_service_start_when_run_in_service_more(ApplicationModes applicationModes) + public void Route_should_call_service_start_when_run_in_service_mode(ApplicationModes applicationModes) { var envMock = Mocker.GetMock(); var serviceProvider = Mocker.GetMock(); @@ -70,6 +70,7 @@ namespace NzbDrone.App.Test envMock.SetupGet(c => c.IsUserInteractive).Returns(false); serviceProvider.Setup(c => c.Run(It.IsAny())); + serviceProvider.Setup(c => c.ServiceExist(It.IsAny())).Returns(true); Subject.Route(applicationModes); diff --git a/NzbDrone.Common/ServiceProvider.cs b/NzbDrone.Common/ServiceProvider.cs index 71460b41a..ea44f5d6c 100644 --- a/NzbDrone.Common/ServiceProvider.cs +++ b/NzbDrone.Common/ServiceProvider.cs @@ -15,7 +15,6 @@ namespace NzbDrone.Common void Install(string serviceName); void UnInstall(string serviceName); void Run(ServiceBase service); - ServiceController GetService(string serviceName); void Stop(string serviceName); void Start(string serviceName); } @@ -26,7 +25,7 @@ namespace NzbDrone.Common private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); - public virtual bool ServiceExist(string name) + public bool ServiceExist(string name) { Logger.Debug("Checking if service {0} exists.", name); return @@ -34,7 +33,7 @@ namespace NzbDrone.Common s => String.Equals(s.ServiceName, name, StringComparison.InvariantCultureIgnoreCase)); } - public virtual bool IsServiceRunning(string name) + public bool IsServiceRunning(string name) { Logger.Debug("Checking if '{0}' service is running", name); @@ -42,13 +41,13 @@ namespace NzbDrone.Common .SingleOrDefault(s => String.Equals(s.ServiceName, name, StringComparison.InvariantCultureIgnoreCase)); return service != null && ( - service.Status != ServiceControllerStatus.Stopped || - service.Status == ServiceControllerStatus.StopPending || - service.Status == ServiceControllerStatus.Paused || + service.Status != ServiceControllerStatus.Stopped || + service.Status == ServiceControllerStatus.StopPending || + service.Status == ServiceControllerStatus.Paused || service.Status == ServiceControllerStatus.PausePending); } - public virtual void Install(string serviceName) + public void Install(string serviceName) { Logger.Info("Installing service '{0}'", serviceName); @@ -77,7 +76,7 @@ namespace NzbDrone.Common Logger.Info("Service Has installed successfully."); } - public virtual void UnInstall(string serviceName) + public void UnInstall(string serviceName) { Logger.Info("Uninstalling {0} service", serviceName); @@ -93,17 +92,17 @@ namespace NzbDrone.Common Logger.Info("{0} successfully uninstalled", serviceName); } - public virtual void Run(ServiceBase service) + public void Run(ServiceBase service) { ServiceBase.Run(service); } - public virtual ServiceController GetService(string serviceName) + public ServiceController GetService(string serviceName) { return ServiceController.GetServices().FirstOrDefault(c => String.Equals(c.ServiceName, serviceName, StringComparison.InvariantCultureIgnoreCase)); } - public virtual void Stop(string serviceName) + public void Stop(string serviceName) { Logger.Info("Stopping {0} Service...", serviceName); var service = GetService(serviceName); @@ -136,7 +135,7 @@ namespace NzbDrone.Common } } - public virtual void Start(string serviceName) + public void Start(string serviceName) { Logger.Info("Starting {0} Service...", serviceName); var service = GetService(serviceName); diff --git a/NzbDrone.Host/Router.cs b/NzbDrone.Host/Router.cs index 960f5bb6a..eb27a8aa3 100644 --- a/NzbDrone.Host/Router.cs +++ b/NzbDrone.Host/Router.cs @@ -32,7 +32,7 @@ namespace NzbDrone.Host public void Route(ApplicationModes applicationModes) { - if (!_runtimeInfo.IsUserInteractive && !OsInfo.IsLinux) + if (!_runtimeInfo.IsUserInteractive && !OsInfo.IsLinux &&_serviceProvider.ServiceExist(ServiceProvider.NZBDRONE_SERVICE_NAME)) { applicationModes = ApplicationModes.Service; }