The Free Software Media System - Server Backend & API
Merge command line options into framework configuration
Mark Monteiro2a0153737131
diff --git a/Jellyfin.Server/Program.cs b/Jellyfin.Server/Program.csindex cb886b8ce0..bfb2fc6b57 100644--- a/Jellyfin.Server/Program.cs+++ b/Jellyfin.Server/Program.cs@@ -113,9 +113,10 @@ namespace Jellyfin.Server// $JELLYFIN_LOG_DIR needs to be set for the logger configuration managerEnvironment.SetEnvironmentVariable("JELLYFIN_LOG_DIR", appPaths.LogDirectoryPath);- // Create an instance of the application configuration to use for application startupawait InitLoggingConfigFile(appPaths).ConfigureAwait(false);- IConfiguration startupConfig = CreateAppConfiguration(appPaths);++ // Create an instance of the application configuration to use for application startup+ IConfiguration startupConfig = CreateAppConfiguration(options, appPaths);// Initialize logging frameworkInitializeLoggingFramework(startupConfig, appPaths);@@ -189,7 +190,7 @@ namespace Jellyfin.ServerServiceCollection serviceCollection = new ServiceCollection();await appHost.InitAsync(serviceCollection, startupConfig).ConfigureAwait(false);- var webHost = CreateWebHostBuilder(appHost, serviceCollection, startupConfig, appPaths).Build();+ var webHost = CreateWebHostBuilder(appHost, serviceCollection, options, startupConfig, appPaths).Build();// Re-use the web host service provider in the app host since ASP.NET doesn't allow a custom service collection.appHost.ServiceProvider = webHost.Services;@@ -238,6 +239,7 @@ namespace Jellyfin.Serverprivate static IWebHostBuilder CreateWebHostBuilder(ApplicationHost appHost,IServiceCollection serviceCollection,+ StartupOptions commandLineOpts,IConfiguration startupConfig,IApplicationPaths appPaths){@@ -279,7 +281,7 @@ namespace Jellyfin.Server}}})- .ConfigureAppConfiguration(config => config.ConfigureAppConfiguration(appPaths, startupConfig))+ .ConfigureAppConfiguration(config => config.ConfigureAppConfiguration(commandLineOpts, appPaths, startupConfig)).UseSerilog().ConfigureServices(services =>{@@ -493,14 +495,18 @@ namespace Jellyfin.Serverawait resource.CopyToAsync(dst).ConfigureAwait(false);}- private static IConfiguration CreateAppConfiguration(IApplicationPaths appPaths)+ private static IConfiguration CreateAppConfiguration(StartupOptions commandLineOpts, IApplicationPaths appPaths){return new ConfigurationBuilder()- .ConfigureAppConfiguration(appPaths)+ .ConfigureAppConfiguration(commandLineOpts, appPaths).Build();}- private static IConfigurationBuilder ConfigureAppConfiguration(this IConfigurationBuilder config, IApplicationPaths appPaths, IConfiguration? startupConfig = null)+ private static IConfigurationBuilder ConfigureAppConfiguration(+ this IConfigurationBuilder config,+ StartupOptions commandLineOpts,+ IApplicationPaths appPaths,+ IConfiguration? startupConfig = null){// Use the swagger API page as the default redirect path if not hosting the jellyfin-web contentvar inMemoryDefaultConfig = ConfigurationOptions.DefaultConfiguration;@@ -514,7 +520,8 @@ namespace Jellyfin.Server.AddInMemoryCollection(inMemoryDefaultConfig).AddJsonFile(LoggingConfigFileDefault, optional: false, reloadOnChange: true).AddJsonFile(LoggingConfigFileSystem, optional: true, reloadOnChange: true)- .AddEnvironmentVariables("JELLYFIN_");+ .AddEnvironmentVariables("JELLYFIN_")+ .AddInMemoryCollection(commandLineOpts.ConvertToConfig());}/// <summary>diff --git a/Jellyfin.Server/StartupOptions.cs b/Jellyfin.Server/StartupOptions.csindex 42c5fa86e3..0f15488f40 100644--- a/Jellyfin.Server/StartupOptions.cs+++ b/Jellyfin.Server/StartupOptions.cs@@ -1,5 +1,8 @@+using System.Collections.Generic;+using System.Globalization;using CommandLine;using Emby.Server.Implementations;+using MediaBrowser.Controller.Extensions;namespace Jellyfin.Server{@@ -72,5 +75,15 @@ namespace Jellyfin.Server/// <inheritdoc />[Option("restartargs", Required = false, HelpText = "Arguments for restart script.")]public string? RestartArgs { get; set; }++ /// <summary>+ /// Gets the command line options as a dictionary that can be used in the .NET configuration system.+ /// </summary>+ /// <returns>The configuration dictionary.</returns>+ public Dictionary<string, string> ConvertToConfig()+ => new Dictionary<string, string>+ {+ { ConfigurationExtensions.NoWebContentKey, NoWebContent.ToString(CultureInfo.InvariantCulture) }+ };}}