Shutdown! Restart working for services

This commit is contained in:
Mark McDowall
2014-01-12 17:14:57 -08:00
parent 119a4ff39c
commit f69bb79077
11 changed files with 155 additions and 22 deletions
@@ -13,25 +13,23 @@ namespace NzbDrone.Common.EnvironmentInfo
bool IsUserInteractive { get; }
bool IsAdmin { get; }
bool IsWindowsService { get; }
bool IsConsole { get; }
bool IsRunning { get; set; }
}
public class RuntimeInfo : IRuntimeInfo
{
private readonly Logger _logger;
private static readonly string ProcessName = Process.GetCurrentProcess().ProcessName.ToLower();
public RuntimeInfo(Logger logger, IServiceProvider serviceProvider)
{
_logger = logger;
IsWindowsService = !IsUserInteractive &&
OsInfo.IsWindows &&
serviceProvider.ServiceExist(ServiceProvider.NZBDRONE_SERVICE_NAME) &&
serviceProvider.GetStatus(ServiceProvider.NZBDRONE_SERVICE_NAME) == ServiceControllerStatus.StartPending;
}
public bool IsUserInteractive
{
get { return Environment.UserInteractive; }
OsInfo.IsWindows &&
serviceProvider.ServiceExist(ServiceProvider.NZBDRONE_SERVICE_NAME) &&
serviceProvider.GetStatus(ServiceProvider.NZBDRONE_SERVICE_NAME) == ServiceControllerStatus.StartPending;
}
static RuntimeInfo()
@@ -39,6 +37,11 @@ namespace NzbDrone.Common.EnvironmentInfo
IsProduction = InternalIsProduction();
}
public bool IsUserInteractive
{
get { return Environment.UserInteractive; }
}
public bool IsAdmin
{
get
@@ -58,7 +61,18 @@ namespace NzbDrone.Common.EnvironmentInfo
public bool IsWindowsService { get; private set; }
private static readonly string ProcessName = Process.GetCurrentProcess().ProcessName.ToLower();
public bool IsConsole
{
get
{
return (OsInfo.IsWindows &&
IsUserInteractive &&
ProcessName.Equals("NzbDrone.Console.exe", StringComparison.InvariantCultureIgnoreCase)) ||
OsInfo.IsLinux;
}
}
public bool IsRunning { get; set; }
public static bool IsProduction { get; private set; }