diff options
| author | Mark Monteiro <marknr.monteiro@protonmail.com> | 2020-03-15 15:34:09 +0100 |
|---|---|---|
| committer | Mark Monteiro <marknr.monteiro@protonmail.com> | 2020-03-15 15:34:09 +0100 |
| commit | 2a0153737131a404a8ccd386ad09ff4a1a697dfc (patch) | |
| tree | 2a8b37bc0382f23a1a4f8693eca44306751ad7d4 | |
| parent | 0996ce28987027afe5943ca9787d4a5695c2ee0a (diff) | |
Merge command line options into framework configuration
| -rw-r--r-- | Jellyfin.Server/Program.cs | 23 | ||||
| -rw-r--r-- | Jellyfin.Server/StartupOptions.cs | 13 |
2 files changed, 28 insertions, 8 deletions
diff --git a/Jellyfin.Server/Program.cs b/Jellyfin.Server/Program.cs index cb886b8ce..bfb2fc6b5 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 manager Environment.SetEnvironmentVariable("JELLYFIN_LOG_DIR", appPaths.LogDirectoryPath); - // Create an instance of the application configuration to use for application startup await 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 framework InitializeLoggingFramework(startupConfig, appPaths); @@ -189,7 +190,7 @@ namespace Jellyfin.Server ServiceCollection 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.Server private 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.Server await 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 content var 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.cs index 42c5fa86e..0f15488f4 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) } + }; } } |
