2021-08-04 20:42:40 +00:00
|
|
|
using System.IO;
|
2018-01-14 22:11:37 +00:00
|
|
|
using System.Threading.Tasks;
|
2021-08-04 20:42:40 +00:00
|
|
|
using Lidarr.Http;
|
|
|
|
using Lidarr.Http.Validation;
|
|
|
|
using Microsoft.AspNetCore.Mvc;
|
|
|
|
using Microsoft.AspNetCore.Routing;
|
|
|
|
using Microsoft.AspNetCore.Routing.Internal;
|
2017-09-04 02:20:56 +00:00
|
|
|
using NzbDrone.Common.EnvironmentInfo;
|
|
|
|
using NzbDrone.Common.Extensions;
|
|
|
|
using NzbDrone.Core.Configuration;
|
|
|
|
using NzbDrone.Core.Datastore;
|
|
|
|
using NzbDrone.Core.Lifecycle;
|
|
|
|
|
2017-10-31 01:28:29 +00:00
|
|
|
namespace Lidarr.Api.V1.System
|
2017-09-04 02:20:56 +00:00
|
|
|
{
|
2021-08-04 20:42:40 +00:00
|
|
|
[V1ApiController]
|
|
|
|
public class SystemController : Controller
|
2017-09-04 02:20:56 +00:00
|
|
|
{
|
|
|
|
private readonly IAppFolderInfo _appFolderInfo;
|
|
|
|
private readonly IRuntimeInfo _runtimeInfo;
|
|
|
|
private readonly IPlatformInfo _platformInfo;
|
|
|
|
private readonly IOsInfo _osInfo;
|
|
|
|
private readonly IConfigFileProvider _configFileProvider;
|
|
|
|
private readonly IMainDatabase _database;
|
|
|
|
private readonly ILifecycleService _lifecycleService;
|
2020-04-03 02:25:09 +00:00
|
|
|
private readonly IDeploymentInfoProvider _deploymentInfoProvider;
|
2021-08-04 20:42:40 +00:00
|
|
|
private readonly EndpointDataSource _endpointData;
|
|
|
|
private readonly DfaGraphWriter _graphWriter;
|
|
|
|
private readonly DuplicateEndpointDetector _detector;
|
2017-09-04 02:20:56 +00:00
|
|
|
|
2021-08-04 20:42:40 +00:00
|
|
|
public SystemController(IAppFolderInfo appFolderInfo,
|
|
|
|
IRuntimeInfo runtimeInfo,
|
|
|
|
IPlatformInfo platformInfo,
|
|
|
|
IOsInfo osInfo,
|
|
|
|
IConfigFileProvider configFileProvider,
|
|
|
|
IMainDatabase database,
|
|
|
|
ILifecycleService lifecycleService,
|
|
|
|
IDeploymentInfoProvider deploymentInfoProvider,
|
|
|
|
EndpointDataSource endpoints,
|
|
|
|
DfaGraphWriter graphWriter,
|
|
|
|
DuplicateEndpointDetector detector)
|
2017-09-04 02:20:56 +00:00
|
|
|
{
|
|
|
|
_appFolderInfo = appFolderInfo;
|
|
|
|
_runtimeInfo = runtimeInfo;
|
|
|
|
_platformInfo = platformInfo;
|
|
|
|
_osInfo = osInfo;
|
|
|
|
_configFileProvider = configFileProvider;
|
|
|
|
_database = database;
|
|
|
|
_lifecycleService = lifecycleService;
|
2020-04-03 02:25:09 +00:00
|
|
|
_deploymentInfoProvider = deploymentInfoProvider;
|
2021-08-04 20:42:40 +00:00
|
|
|
_endpointData = endpoints;
|
|
|
|
_graphWriter = graphWriter;
|
|
|
|
_detector = detector;
|
2017-09-04 02:20:56 +00:00
|
|
|
}
|
|
|
|
|
2021-08-04 20:42:40 +00:00
|
|
|
[HttpGet("status")]
|
|
|
|
public object GetStatus()
|
2017-09-04 02:20:56 +00:00
|
|
|
{
|
|
|
|
return new
|
2018-08-08 00:57:15 +00:00
|
|
|
{
|
2022-01-19 05:28:12 +00:00
|
|
|
AppName = BuildInfo.AppName,
|
2022-05-13 00:07:40 +00:00
|
|
|
InstanceName = _configFileProvider.InstanceName,
|
2017-09-04 02:20:56 +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,
|
2022-10-16 01:26:01 +00:00
|
|
|
IsNetCore = true,
|
2017-09-04 02:20:56 +00:00
|
|
|
IsLinux = OsInfo.IsLinux,
|
|
|
|
IsOsx = OsInfo.IsOsx,
|
|
|
|
IsWindows = OsInfo.IsWindows,
|
2019-04-05 15:47:26 +00:00
|
|
|
IsDocker = _osInfo.IsDocker,
|
2017-09-04 02:20:56 +00:00
|
|
|
Mode = _runtimeInfo.Mode,
|
|
|
|
Branch = _configFileProvider.Branch,
|
|
|
|
Authentication = _configFileProvider.AuthenticationMethod,
|
2022-01-26 00:08:27 +00:00
|
|
|
DatabaseType = _database.DatabaseType,
|
|
|
|
DatabaseVersion = _database.Version,
|
2017-11-16 16:07:42 +00:00
|
|
|
MigrationVersion = _database.Migration,
|
2017-09-04 02:20:56 +00:00
|
|
|
UrlBase = _configFileProvider.UrlBase,
|
|
|
|
RuntimeVersion = _platformInfo.Version,
|
2022-10-16 01:26:01 +00:00
|
|
|
RuntimeName = "netcore",
|
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-09-12 20:32:51 +00:00
|
|
|
};
|
2017-09-04 02:20:56 +00:00
|
|
|
}
|
|
|
|
|
2021-08-04 20:42:40 +00:00
|
|
|
[HttpGet("routes")]
|
|
|
|
public IActionResult GetRoutes()
|
2017-09-04 02:20:56 +00:00
|
|
|
{
|
2021-08-04 20:42:40 +00:00
|
|
|
using (var sw = new StringWriter())
|
|
|
|
{
|
|
|
|
_graphWriter.Write(_endpointData, sw);
|
|
|
|
var graph = sw.ToString();
|
|
|
|
return Content(graph, "text/plain");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
[HttpGet("routes/duplicate")]
|
|
|
|
public object DuplicateRoutes()
|
|
|
|
{
|
|
|
|
return _detector.GetDuplicateEndpoints(_endpointData);
|
2017-09-04 02:20:56 +00:00
|
|
|
}
|
|
|
|
|
2021-08-04 20:42:40 +00:00
|
|
|
[HttpPost("shutdown")]
|
|
|
|
public object Shutdown()
|
2017-09-04 02:20:56 +00:00
|
|
|
{
|
2018-01-14 22:11:37 +00:00
|
|
|
Task.Factory.StartNew(() => _lifecycleService.Shutdown());
|
2019-09-12 20:32:51 +00:00
|
|
|
return new { ShuttingDown = true };
|
2017-09-04 02:20:56 +00:00
|
|
|
}
|
|
|
|
|
2021-08-04 20:42:40 +00:00
|
|
|
[HttpPost("restart")]
|
|
|
|
public object Restart()
|
2017-09-04 02:20:56 +00:00
|
|
|
{
|
2018-01-14 22:11:37 +00:00
|
|
|
Task.Factory.StartNew(() => _lifecycleService.Restart());
|
2019-09-12 20:32:51 +00:00
|
|
|
return new { Restarting = true };
|
2017-09-04 02:20:56 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|