mirror of
https://github.com/lidarr/Lidarr
synced 2024-12-27 01:57:21 +00:00
don't attempt to run in service mode if service is not installed.
This commit is contained in:
parent
bfa817922e
commit
9689b07d5b
3 changed files with 14 additions and 14 deletions
|
@ -62,7 +62,7 @@ public void Route_should_call_console_service_when_application_mode_is_console()
|
||||||
[TestCase(ApplicationModes.InstallService)]
|
[TestCase(ApplicationModes.InstallService)]
|
||||||
[TestCase(ApplicationModes.UninstallService)]
|
[TestCase(ApplicationModes.UninstallService)]
|
||||||
[TestCase(ApplicationModes.Help)]
|
[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<IRuntimeInfo>();
|
var envMock = Mocker.GetMock<IRuntimeInfo>();
|
||||||
var serviceProvider = Mocker.GetMock<IServiceProvider>();
|
var serviceProvider = Mocker.GetMock<IServiceProvider>();
|
||||||
|
@ -70,6 +70,7 @@ public void Route_should_call_service_start_when_run_in_service_more(Application
|
||||||
envMock.SetupGet(c => c.IsUserInteractive).Returns(false);
|
envMock.SetupGet(c => c.IsUserInteractive).Returns(false);
|
||||||
|
|
||||||
serviceProvider.Setup(c => c.Run(It.IsAny<ServiceBase>()));
|
serviceProvider.Setup(c => c.Run(It.IsAny<ServiceBase>()));
|
||||||
|
serviceProvider.Setup(c => c.ServiceExist(It.IsAny<string>())).Returns(true);
|
||||||
|
|
||||||
Subject.Route(applicationModes);
|
Subject.Route(applicationModes);
|
||||||
|
|
||||||
|
|
|
@ -15,7 +15,6 @@ public interface IServiceProvider
|
||||||
void Install(string serviceName);
|
void Install(string serviceName);
|
||||||
void UnInstall(string serviceName);
|
void UnInstall(string serviceName);
|
||||||
void Run(ServiceBase service);
|
void Run(ServiceBase service);
|
||||||
ServiceController GetService(string serviceName);
|
|
||||||
void Stop(string serviceName);
|
void Stop(string serviceName);
|
||||||
void Start(string serviceName);
|
void Start(string serviceName);
|
||||||
}
|
}
|
||||||
|
@ -26,7 +25,7 @@ public class ServiceProvider : IServiceProvider
|
||||||
|
|
||||||
private static readonly Logger Logger = LogManager.GetCurrentClassLogger();
|
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);
|
Logger.Debug("Checking if service {0} exists.", name);
|
||||||
return
|
return
|
||||||
|
@ -34,7 +33,7 @@ public virtual bool ServiceExist(string name)
|
||||||
s => String.Equals(s.ServiceName, name, StringComparison.InvariantCultureIgnoreCase));
|
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);
|
Logger.Debug("Checking if '{0}' service is running", name);
|
||||||
|
|
||||||
|
@ -48,7 +47,7 @@ public virtual bool IsServiceRunning(string name)
|
||||||
service.Status == ServiceControllerStatus.PausePending);
|
service.Status == ServiceControllerStatus.PausePending);
|
||||||
}
|
}
|
||||||
|
|
||||||
public virtual void Install(string serviceName)
|
public void Install(string serviceName)
|
||||||
{
|
{
|
||||||
Logger.Info("Installing service '{0}'", serviceName);
|
Logger.Info("Installing service '{0}'", serviceName);
|
||||||
|
|
||||||
|
@ -77,7 +76,7 @@ public virtual void Install(string serviceName)
|
||||||
Logger.Info("Service Has installed successfully.");
|
Logger.Info("Service Has installed successfully.");
|
||||||
}
|
}
|
||||||
|
|
||||||
public virtual void UnInstall(string serviceName)
|
public void UnInstall(string serviceName)
|
||||||
{
|
{
|
||||||
Logger.Info("Uninstalling {0} service", serviceName);
|
Logger.Info("Uninstalling {0} service", serviceName);
|
||||||
|
|
||||||
|
@ -93,17 +92,17 @@ public virtual void UnInstall(string serviceName)
|
||||||
Logger.Info("{0} successfully uninstalled", serviceName);
|
Logger.Info("{0} successfully uninstalled", serviceName);
|
||||||
}
|
}
|
||||||
|
|
||||||
public virtual void Run(ServiceBase service)
|
public void Run(ServiceBase service)
|
||||||
{
|
{
|
||||||
ServiceBase.Run(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));
|
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);
|
Logger.Info("Stopping {0} Service...", serviceName);
|
||||||
var service = GetService(serviceName);
|
var service = GetService(serviceName);
|
||||||
|
@ -136,7 +135,7 @@ public virtual void Stop(string serviceName)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public virtual void Start(string serviceName)
|
public void Start(string serviceName)
|
||||||
{
|
{
|
||||||
Logger.Info("Starting {0} Service...", serviceName);
|
Logger.Info("Starting {0} Service...", serviceName);
|
||||||
var service = GetService(serviceName);
|
var service = GetService(serviceName);
|
||||||
|
|
|
@ -32,7 +32,7 @@ public void Route()
|
||||||
|
|
||||||
public void Route(ApplicationModes applicationModes)
|
public void Route(ApplicationModes applicationModes)
|
||||||
{
|
{
|
||||||
if (!_runtimeInfo.IsUserInteractive && !OsInfo.IsLinux)
|
if (!_runtimeInfo.IsUserInteractive && !OsInfo.IsLinux &&_serviceProvider.ServiceExist(ServiceProvider.NZBDRONE_SERVICE_NAME))
|
||||||
{
|
{
|
||||||
applicationModes = ApplicationModes.Service;
|
applicationModes = ApplicationModes.Service;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue