2018-11-23 07:03:32 +00:00
|
|
|
using System.Threading.Tasks;
|
|
|
|
using Nancy.Routing;
|
|
|
|
using NzbDrone.Common.EnvironmentInfo;
|
|
|
|
using NzbDrone.Common.Extensions;
|
|
|
|
using NzbDrone.Core.Configuration;
|
|
|
|
using NzbDrone.Core.Datastore;
|
|
|
|
using NzbDrone.Core.Lifecycle;
|
|
|
|
|
2019-12-03 01:36:18 +00:00
|
|
|
namespace Radarr.Api.V3.System
|
2018-11-23 07:03:32 +00:00
|
|
|
{
|
2019-12-03 01:36:18 +00:00
|
|
|
public class SystemModule : RadarrV3Module
|
2018-11-23 07:03:32 +00:00
|
|
|
{
|
|
|
|
private readonly IAppFolderInfo _appFolderInfo;
|
|
|
|
private readonly IRuntimeInfo _runtimeInfo;
|
|
|
|
private readonly IPlatformInfo _platformInfo;
|
|
|
|
private readonly IOsInfo _osInfo;
|
|
|
|
private readonly IRouteCacheProvider _routeCacheProvider;
|
|
|
|
private readonly IConfigFileProvider _configFileProvider;
|
|
|
|
private readonly IMainDatabase _database;
|
|
|
|
private readonly ILifecycleService _lifecycleService;
|
2020-04-03 02:25:09 +00:00
|
|
|
private readonly IDeploymentInfoProvider _deploymentInfoProvider;
|
2018-11-23 07:03:32 +00:00
|
|
|
|
|
|
|
public SystemModule(IAppFolderInfo appFolderInfo,
|
|
|
|
IRuntimeInfo runtimeInfo,
|
|
|
|
IPlatformInfo platformInfo,
|
|
|
|
IOsInfo osInfo,
|
|
|
|
IRouteCacheProvider routeCacheProvider,
|
|
|
|
IConfigFileProvider configFileProvider,
|
|
|
|
IMainDatabase database,
|
2020-04-03 02:25:09 +00:00
|
|
|
ILifecycleService lifecycleService,
|
|
|
|
IDeploymentInfoProvider deploymentInfoProvider)
|
2018-11-23 07:03:32 +00:00
|
|
|
: base("system")
|
|
|
|
{
|
|
|
|
_appFolderInfo = appFolderInfo;
|
|
|
|
_runtimeInfo = runtimeInfo;
|
|
|
|
_platformInfo = platformInfo;
|
|
|
|
_osInfo = osInfo;
|
|
|
|
_routeCacheProvider = routeCacheProvider;
|
|
|
|
_configFileProvider = configFileProvider;
|
|
|
|
_database = database;
|
|
|
|
_lifecycleService = lifecycleService;
|
2020-04-03 02:25:09 +00:00
|
|
|
_deploymentInfoProvider = deploymentInfoProvider;
|
2019-12-22 22:08:53 +00:00
|
|
|
Get("/status", x => GetStatus());
|
|
|
|
Get("/routes", x => GetRoutes());
|
|
|
|
Post("/shutdown", x => Shutdown());
|
|
|
|
Post("/restart", x => Restart());
|
2018-11-23 07:03:32 +00:00
|
|
|
}
|
|
|
|
|
2019-08-28 21:43:55 +00:00
|
|
|
private object GetStatus()
|
2018-11-23 07:03:32 +00:00
|
|
|
{
|
|
|
|
return new
|
2019-12-22 22:08:53 +00:00
|
|
|
{
|
|
|
|
Version = BuildInfo.Version.ToString(),
|
|
|
|
BuildTime = BuildInfo.BuildDateTime,
|
|
|
|
IsDebug = BuildInfo.IsDebug,
|
|
|
|
IsProduction = RuntimeInfo.IsProduction,
|
|
|
|
IsAdmin = _runtimeInfo.IsAdmin,
|
|
|
|
IsUserInteractive = RuntimeInfo.IsUserInteractive,
|
|
|
|
StartupPath = _appFolderInfo.StartUpFolder,
|
|
|
|
AppData = _appFolderInfo.GetAppDataPath(),
|
|
|
|
OsName = _osInfo.Name,
|
|
|
|
OsVersion = _osInfo.Version,
|
|
|
|
IsNetCore = PlatformInfo.IsNetCore,
|
|
|
|
IsMono = PlatformInfo.IsMono,
|
|
|
|
IsLinux = OsInfo.IsLinux,
|
|
|
|
IsOsx = OsInfo.IsOsx,
|
|
|
|
IsWindows = OsInfo.IsWindows,
|
|
|
|
IsDocker = _osInfo.IsDocker,
|
|
|
|
Mode = _runtimeInfo.Mode,
|
|
|
|
Branch = _configFileProvider.Branch,
|
|
|
|
Authentication = _configFileProvider.AuthenticationMethod,
|
|
|
|
SqliteVersion = _database.Version,
|
|
|
|
MigrationVersion = _database.Migration,
|
|
|
|
UrlBase = _configFileProvider.UrlBase,
|
|
|
|
RuntimeVersion = _platformInfo.Version,
|
|
|
|
RuntimeName = PlatformInfo.Platform,
|
2020-04-03 02:25:09 +00:00
|
|
|
StartTime = _runtimeInfo.StartTime,
|
|
|
|
PackageVersion = _deploymentInfoProvider.PackageVersion,
|
|
|
|
PackageAuthor = _deploymentInfoProvider.PackageAuthor,
|
2020-05-03 15:28:18 +00:00
|
|
|
PackageUpdateMechanism = _deploymentInfoProvider.PackageUpdateMechanism,
|
|
|
|
PackageUpdateMechanismMessage = _deploymentInfoProvider.PackageUpdateMechanismMessage
|
2019-12-22 22:08:53 +00:00
|
|
|
};
|
2018-11-23 07:03:32 +00:00
|
|
|
}
|
|
|
|
|
2019-08-28 21:43:55 +00:00
|
|
|
private object GetRoutes()
|
2018-11-23 07:03:32 +00:00
|
|
|
{
|
2019-08-28 21:43:55 +00:00
|
|
|
return _routeCacheProvider.GetCache().Values;
|
2018-11-23 07:03:32 +00:00
|
|
|
}
|
|
|
|
|
2019-08-28 21:43:55 +00:00
|
|
|
private object Shutdown()
|
2018-11-23 07:03:32 +00:00
|
|
|
{
|
|
|
|
Task.Factory.StartNew(() => _lifecycleService.Shutdown());
|
2019-08-28 21:43:55 +00:00
|
|
|
return new { ShuttingDown = true };
|
2018-11-23 07:03:32 +00:00
|
|
|
}
|
|
|
|
|
2019-08-28 21:43:55 +00:00
|
|
|
private object Restart()
|
2018-11-23 07:03:32 +00:00
|
|
|
{
|
|
|
|
Task.Factory.StartNew(() => _lifecycleService.Restart());
|
2019-08-28 21:43:55 +00:00
|
|
|
return new { Restarting = true };
|
2018-11-23 07:03:32 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|