better service routing

pull/6/head
kay.one 12 years ago
parent 9689b07d5b
commit 3b4eacdd31

@ -2,6 +2,7 @@
using System.Diagnostics;
using System.IO;
using System.Security.Principal;
using System.ServiceProcess;
using NLog;
namespace NzbDrone.Common.EnvironmentInfo

@ -15,6 +15,7 @@ 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);
}
@ -25,7 +26,7 @@ namespace NzbDrone.Common
private static readonly Logger Logger = LogManager.GetCurrentClassLogger();
public bool ServiceExist(string name)
public virtual bool ServiceExist(string name)
{
Logger.Debug("Checking if service {0} exists.", name);
return
@ -33,7 +34,7 @@ namespace NzbDrone.Common
s => String.Equals(s.ServiceName, name, StringComparison.InvariantCultureIgnoreCase));
}
public bool IsServiceRunning(string name)
public virtual bool IsServiceRunning(string name)
{
Logger.Debug("Checking if '{0}' service is running", name);
@ -47,7 +48,7 @@ namespace NzbDrone.Common
service.Status == ServiceControllerStatus.PausePending);
}
public void Install(string serviceName)
public virtual void Install(string serviceName)
{
Logger.Info("Installing service '{0}'", serviceName);
@ -76,7 +77,7 @@ namespace NzbDrone.Common
Logger.Info("Service Has installed successfully.");
}
public void UnInstall(string serviceName)
public virtual void UnInstall(string serviceName)
{
Logger.Info("Uninstalling {0} service", serviceName);
@ -92,17 +93,17 @@ namespace NzbDrone.Common
Logger.Info("{0} successfully uninstalled", serviceName);
}
public void Run(ServiceBase service)
public virtual void Run(ServiceBase service)
{
ServiceBase.Run(service);
}
public ServiceController GetService(string serviceName)
public virtual ServiceController GetService(string serviceName)
{
return ServiceController.GetServices().FirstOrDefault(c => String.Equals(c.ServiceName, serviceName, StringComparison.InvariantCultureIgnoreCase));
}
public void Stop(string serviceName)
public virtual void Stop(string serviceName)
{
Logger.Info("Stopping {0} Service...", serviceName);
var service = GetService(serviceName);
@ -135,7 +136,7 @@ namespace NzbDrone.Common
}
}
public void Start(string serviceName)
public virtual void Start(string serviceName)
{
Logger.Info("Starting {0} Service...", serviceName);
var service = GetService(serviceName);

@ -1,4 +1,5 @@
using NLog;
using System.ServiceProcess;
using NLog;
using NzbDrone.Common;
using NzbDrone.Common.EnvironmentInfo;
@ -32,11 +33,6 @@ namespace NzbDrone.Host
public void Route(ApplicationModes applicationModes)
{
if (!_runtimeInfo.IsUserInteractive && !OsInfo.IsLinux &&_serviceProvider.ServiceExist(ServiceProvider.NZBDRONE_SERVICE_NAME))
{
applicationModes = ApplicationModes.Service;
}
_logger.Info("Application mode: {0}", applicationModes);
switch (applicationModes)
@ -112,6 +108,14 @@ namespace NzbDrone.Host
return ApplicationModes.UninstallService;
}
if (!_runtimeInfo.IsUserInteractive &&
OsInfo.IsWindows &&
_serviceProvider.ServiceExist(ServiceProvider.NZBDRONE_SERVICE_NAME) &&
_serviceProvider.GetService(ServiceProvider.NZBDRONE_SERVICE_NAME).Status == ServiceControllerStatus.StartPending)
{
return ApplicationModes.Service;
}
return ApplicationModes.Interactive;
}
}

Loading…
Cancel
Save