From a36216c73ca8aa784ee151d4669c8c9148caba94 Mon Sep 17 00:00:00 2001 From: "kay.one" Date: Mon, 20 May 2013 13:22:27 -0700 Subject: [PATCH] added /system/status end point that returns environment information. --- NzbDrone.Api/NzbDrone.Api.csproj | 1 + NzbDrone.Api/System/SystemModule.cs | 37 +++++++++++++++++++++++++++++ NzbDrone.Common/IServiceProvider.cs | 2 +- 3 files changed, 39 insertions(+), 1 deletion(-) create mode 100644 NzbDrone.Api/System/SystemModule.cs diff --git a/NzbDrone.Api/NzbDrone.Api.csproj b/NzbDrone.Api/NzbDrone.Api.csproj index d23daf537..52ced19fc 100644 --- a/NzbDrone.Api/NzbDrone.Api.csproj +++ b/NzbDrone.Api/NzbDrone.Api.csproj @@ -150,6 +150,7 @@ + diff --git a/NzbDrone.Api/System/SystemModule.cs b/NzbDrone.Api/System/SystemModule.cs new file mode 100644 index 000000000..80a4056bf --- /dev/null +++ b/NzbDrone.Api/System/SystemModule.cs @@ -0,0 +1,37 @@ +using Nancy; +using NzbDrone.Common; +using NzbDrone.Api.Extensions; + +namespace NzbDrone.Api.System +{ + public class SystemModule : NzbDroneApiModule + { + private readonly IEnvironmentProvider _environmentProvider; + + public SystemModule(IEnvironmentProvider environmentProvider) + : base("system") + { + _environmentProvider = environmentProvider; + Get["/status"] = x => GetStatus(); + } + + private Response GetStatus() + { + return new + { + Version = _environmentProvider.Version, + AppData = _environmentProvider.GetAppDataPath(), + IsAdmin = _environmentProvider.IsAdmin, + IsUserInteractive = _environmentProvider.IsUserInteractive, + BuildTime = _environmentProvider.BuildDateTime, + StartupPath = _environmentProvider.StartUpPath, + OsVersion = _environmentProvider.GetOsVersion(), + IsMono = EnvironmentProvider.IsMono, + IsProduction = EnvironmentProvider.IsProduction, + IsDebug = EnvironmentProvider.IsDebug, + IsLinux = EnvironmentProvider.IsLinux + }.AsResponse(); + + } + } +} diff --git a/NzbDrone.Common/IServiceProvider.cs b/NzbDrone.Common/IServiceProvider.cs index 256ae6182..37e97e8f3 100644 --- a/NzbDrone.Common/IServiceProvider.cs +++ b/NzbDrone.Common/IServiceProvider.cs @@ -41,7 +41,7 @@ namespace NzbDrone.Common var service = ServiceController.GetServices() .SingleOrDefault(s => String.Equals(s.ServiceName, name, StringComparison.InvariantCultureIgnoreCase)); - return service != null && service.Status == ServiceControllerStatus.Running; + return service != null && (service.Status == ServiceControllerStatus.Running || service.Status == ServiceControllerStatus.StartPending); } public virtual void Install(string serviceName)