mirror of https://github.com/Radarr/Radarr
New: toggle log database with a flag in config.xml
This commit is contained in:
parent
f77e27bace
commit
75e173b9ee
|
@ -29,6 +29,7 @@ namespace NzbDrone.Common.Test
|
|||
.AddNzbDroneLogger()
|
||||
.AutoAddServices(Bootstrap.ASSEMBLIES)
|
||||
.AddDummyDatabase()
|
||||
.AddDummyLogDatabase()
|
||||
.AddStartupContext(new StartupContext("first", "second"));
|
||||
|
||||
container.RegisterInstance(new Mock<IHostLifetime>().Object);
|
||||
|
|
|
@ -61,6 +61,7 @@ namespace NzbDrone.Core.Configuration
|
|||
string PostgresMainDb { get; }
|
||||
string PostgresLogDb { get; }
|
||||
string Theme { get; }
|
||||
bool LogDbEnabled { get; }
|
||||
}
|
||||
|
||||
public class ConfigFileProvider : IConfigFileProvider
|
||||
|
@ -202,6 +203,7 @@ namespace NzbDrone.Core.Configuration
|
|||
public string LogLevel => GetValue("LogLevel", "info").ToLowerInvariant();
|
||||
public string ConsoleLogLevel => GetValue("ConsoleLogLevel", string.Empty, persist: false);
|
||||
public string Theme => GetValue("Theme", "auto", persist: false);
|
||||
public bool LogDbEnabled => GetValueBoolean("LogDbEnabled", true, false);
|
||||
public string PostgresHost => _postgresOptions?.Host ?? GetValue("PostgresHost", string.Empty, persist: false);
|
||||
public string PostgresUser => _postgresOptions?.User ?? GetValue("PostgresUser", string.Empty, persist: false);
|
||||
public string PostgresPassword => _postgresOptions?.Password ?? GetValue("PostgresPassword", string.Empty, persist: false);
|
||||
|
|
|
@ -8,14 +8,24 @@ namespace NzbDrone.Core.Datastore.Extensions
|
|||
public static IContainer AddDatabase(this IContainer container)
|
||||
{
|
||||
container.RegisterDelegate<IDbFactory, IMainDatabase>(f => new MainDatabase(f.Create()), Reuse.Singleton);
|
||||
container.RegisterDelegate<IDbFactory, ILogDatabase>(f => new LogDatabase(f.Create(MigrationType.Log)), Reuse.Singleton);
|
||||
return container;
|
||||
}
|
||||
|
||||
public static IContainer AddLogDatabase(this IContainer container)
|
||||
{
|
||||
container.RegisterDelegate<IDbFactory, ILogDatabase>(f => new LogDatabase(f.Create(MigrationType.Log)), Reuse.Singleton);
|
||||
return container;
|
||||
}
|
||||
|
||||
public static IContainer AddDummyDatabase(this IContainer container)
|
||||
{
|
||||
container.RegisterInstance<IMainDatabase>(new MainDatabase(null));
|
||||
|
||||
return container;
|
||||
}
|
||||
|
||||
public static IContainer AddDummyLogDatabase(this IContainer container)
|
||||
{
|
||||
container.RegisterInstance<ILogDatabase>(new LogDatabase(null));
|
||||
|
||||
return container;
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
using System.Collections.Generic;
|
||||
using NLog;
|
||||
using NzbDrone.Common.EnvironmentInfo;
|
||||
using NzbDrone.Core.Configuration;
|
||||
using NzbDrone.Core.Lifecycle;
|
||||
using NzbDrone.Core.Messaging.Events;
|
||||
using NzbDrone.Core.Update.History.Events;
|
||||
|
@ -19,13 +20,15 @@ namespace NzbDrone.Core.Update.History
|
|||
private readonly IUpdateHistoryRepository _repository;
|
||||
private readonly IEventAggregator _eventAggregator;
|
||||
private readonly Logger _logger;
|
||||
private readonly IConfigFileProvider _configFileProvider;
|
||||
private Version _prevVersion;
|
||||
|
||||
public UpdateHistoryService(IUpdateHistoryRepository repository, IEventAggregator eventAggregator, Logger logger)
|
||||
public UpdateHistoryService(IUpdateHistoryRepository repository, IEventAggregator eventAggregator, Logger logger, IConfigFileProvider configFileProvider)
|
||||
{
|
||||
_repository = repository;
|
||||
_eventAggregator = eventAggregator;
|
||||
_logger = logger;
|
||||
_configFileProvider = configFileProvider;
|
||||
}
|
||||
|
||||
public Version PreviouslyInstalled()
|
||||
|
@ -58,7 +61,7 @@ namespace NzbDrone.Core.Update.History
|
|||
|
||||
public void Handle(ApplicationStartedEvent message)
|
||||
{
|
||||
if (BuildInfo.Version.Major == 10)
|
||||
if (BuildInfo.Version.Major == 10 || !_configFileProvider.LogDbEnabled)
|
||||
{
|
||||
// Don't save dev versions, they change constantly
|
||||
return;
|
||||
|
|
|
@ -41,6 +41,7 @@ namespace NzbDrone.App.Test
|
|||
.AutoAddServices(Bootstrap.ASSEMBLIES)
|
||||
.AddNzbDroneLogger()
|
||||
.AddDummyDatabase()
|
||||
.AddDummyLogDatabase()
|
||||
.AddStartupContext(args);
|
||||
|
||||
// dummy lifetime and broadcaster so tests resolve
|
||||
|
|
|
@ -83,23 +83,31 @@ namespace NzbDrone.Host
|
|||
// Utility mode
|
||||
default:
|
||||
{
|
||||
new HostBuilder()
|
||||
.UseServiceProviderFactory(new DryIocServiceProviderFactory(new Container(rules => rules.WithNzbDroneRules())))
|
||||
.ConfigureContainer<IContainer>(c =>
|
||||
{
|
||||
c.AutoAddServices(Bootstrap.ASSEMBLIES)
|
||||
.AddNzbDroneLogger()
|
||||
.AddDatabase()
|
||||
.AddStartupContext(startupContext)
|
||||
.Resolve<UtilityModeRouter>()
|
||||
.Route(appMode);
|
||||
})
|
||||
.ConfigureServices(services =>
|
||||
{
|
||||
services.Configure<PostgresOptions>(config.GetSection("Radarr:Postgres"));
|
||||
}).Build();
|
||||
new HostBuilder()
|
||||
.UseServiceProviderFactory(new DryIocServiceProviderFactory(new Container(rules => rules.WithNzbDroneRules())))
|
||||
.ConfigureContainer<IContainer>(c =>
|
||||
{
|
||||
c.AutoAddServices(Bootstrap.ASSEMBLIES)
|
||||
.AddNzbDroneLogger()
|
||||
.AddDatabase()
|
||||
.AddStartupContext(startupContext)
|
||||
.Resolve<UtilityModeRouter>()
|
||||
.Route(appMode);
|
||||
if (config.GetValue(nameof(ConfigFileProvider.LogDbEnabled), true))
|
||||
{
|
||||
c.AddLogDatabase();
|
||||
}
|
||||
else
|
||||
{
|
||||
c.AddDummyLogDatabase();
|
||||
}
|
||||
})
|
||||
.ConfigureServices(services =>
|
||||
{
|
||||
services.Configure<PostgresOptions>(config.GetSection("Radarr:Postgres"));
|
||||
}).Build();
|
||||
|
||||
break;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -130,6 +138,7 @@ namespace NzbDrone.Host
|
|||
var enableSsl = config.GetValue(nameof(ConfigFileProvider.EnableSsl), false);
|
||||
var sslCertPath = config.GetValue<string>(nameof(ConfigFileProvider.SslCertPath));
|
||||
var sslCertPassword = config.GetValue<string>(nameof(ConfigFileProvider.SslCertPassword));
|
||||
var logDbEnabled = config.GetValue<bool>(nameof(ConfigFileProvider.LogDbEnabled), true);
|
||||
|
||||
var urls = new List<string> { BuildUrl("http", bindAddress, port) };
|
||||
|
||||
|
@ -147,6 +156,14 @@ namespace NzbDrone.Host
|
|||
.AddNzbDroneLogger()
|
||||
.AddDatabase()
|
||||
.AddStartupContext(context);
|
||||
if (logDbEnabled)
|
||||
{
|
||||
c.AddLogDatabase();
|
||||
}
|
||||
else
|
||||
{
|
||||
c.AddDummyLogDatabase();
|
||||
}
|
||||
|
||||
SchemaBuilder.Initialize(c);
|
||||
})
|
||||
|
|
|
@ -236,9 +236,12 @@ namespace NzbDrone.Host
|
|||
|
||||
// instantiate the databases to initialize/migrate them
|
||||
_ = mainDatabaseFactory.Value;
|
||||
_ = logDatabaseFactory.Value;
|
||||
|
||||
dbTarget.Register();
|
||||
if (configFileProvider.LogDbEnabled)
|
||||
{
|
||||
_ = logDatabaseFactory.Value;
|
||||
dbTarget.Register();
|
||||
}
|
||||
|
||||
if (OsInfo.IsNotWindows)
|
||||
{
|
||||
|
|
|
@ -3,10 +3,12 @@ using NzbDrone.Common.Extensions;
|
|||
using NzbDrone.Core.Instrumentation;
|
||||
using Radarr.Http;
|
||||
using Radarr.Http.Extensions;
|
||||
using Radarr.Http.REST.Filters;
|
||||
|
||||
namespace Radarr.Api.V3.Logs
|
||||
{
|
||||
[V3ApiController]
|
||||
[LogDatabaseDisabledActionFilter]
|
||||
public class LogController : Controller
|
||||
{
|
||||
private readonly ILogService _logService;
|
||||
|
|
|
@ -5,10 +5,12 @@ using NzbDrone.Common.EnvironmentInfo;
|
|||
using NzbDrone.Core.Update;
|
||||
using NzbDrone.Core.Update.History;
|
||||
using Radarr.Http;
|
||||
using Radarr.Http.REST.Filters;
|
||||
|
||||
namespace Radarr.Api.V3.Update
|
||||
{
|
||||
[V3ApiController]
|
||||
[LogDatabaseDisabledActionFilter]
|
||||
public class UpdateController : Controller
|
||||
{
|
||||
private readonly IRecentUpdateProvider _recentUpdateProvider;
|
||||
|
|
|
@ -0,0 +1,22 @@
|
|||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.AspNetCore.Mvc.Filters;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using NzbDrone.Core.Configuration;
|
||||
|
||||
namespace Radarr.Http.REST.Filters;
|
||||
|
||||
public class LogDatabaseDisabledActionFilterAttribute : ActionFilterAttribute
|
||||
{
|
||||
public override void OnActionExecuting(ActionExecutingContext context)
|
||||
{
|
||||
var configFileProvider = context.HttpContext.RequestServices.GetService<IConfigFileProvider>();
|
||||
if (!configFileProvider.LogDbEnabled)
|
||||
{
|
||||
context.Result = new NotFoundResult();
|
||||
}
|
||||
}
|
||||
|
||||
public override void OnActionExecuted(ActionExecutedContext context)
|
||||
{
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue