diff options
Diffstat (limited to 'Jellyfin.Server/Program.cs')
| -rw-r--r-- | Jellyfin.Server/Program.cs | 73 |
1 files changed, 34 insertions, 39 deletions
diff --git a/Jellyfin.Server/Program.cs b/Jellyfin.Server/Program.cs index ac5aab460..41ee73a56 100644 --- a/Jellyfin.Server/Program.cs +++ b/Jellyfin.Server/Program.cs @@ -35,6 +35,7 @@ namespace Jellyfin.Server private static readonly ILoggerFactory _loggerFactory = new SerilogLoggerFactory(); private static ILogger _logger; private static bool _restartOnShutdown; + private static IConfiguration appConfig; public static async Task Main(string[] args) { @@ -78,7 +79,11 @@ namespace Jellyfin.Server // $JELLYFIN_LOG_DIR needs to be set for the logger configuration manager Environment.SetEnvironmentVariable("JELLYFIN_LOG_DIR", appPaths.LogDirectoryPath); - await CreateLogger(appPaths).ConfigureAwait(false); + + appConfig = await CreateConfiguration(appPaths).ConfigureAwait(false); + + CreateLogger(appConfig, appPaths); + _logger = _loggerFactory.CreateLogger("Main"); AppDomain.CurrentDomain.UnhandledException += (sender, e) @@ -121,7 +126,7 @@ namespace Jellyfin.Server // Allow all https requests ServicePointManager.ServerCertificateValidationCallback = new RemoteCertificateValidationCallback(delegate { return true; } ); - var fileSystem = new ManagedFileSystem(_loggerFactory, environmentInfo, null, appPaths.TempDirectory, true); + var fileSystem = new ManagedFileSystem(_loggerFactory, environmentInfo, appPaths); using (var appHost = new CoreAppHost( appPaths, @@ -130,7 +135,8 @@ namespace Jellyfin.Server fileSystem, environmentInfo, new NullImageEncoder(), - new NetworkManager(_loggerFactory, environmentInfo))) + new NetworkManager(_loggerFactory, environmentInfo), + appConfig)) { await appHost.Init(new ServiceCollection()).ConfigureAwait(false); @@ -181,26 +187,13 @@ namespace Jellyfin.Server if (string.IsNullOrEmpty(dataDir)) { - if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) - { - dataDir = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData); - } - else - { - // $XDG_DATA_HOME defines the base directory relative to which user specific data files should be stored. - dataDir = Environment.GetEnvironmentVariable("XDG_DATA_HOME"); - - // If $XDG_DATA_HOME is either not set or empty, a default equal to $HOME/.local/share should be used. - if (string.IsNullOrEmpty(dataDir)) - { - dataDir = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile), ".local", "share"); - } - } - - dataDir = Path.Combine(dataDir, "jellyfin"); + // LocalApplicationData follows the XDG spec on unix machines + dataDir = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "jellyfin"); } } + Directory.CreateDirectory(dataDir); + // configDir // IF --configdir // ELSE IF $JELLYFIN_CONFIG_DIR @@ -210,7 +203,6 @@ namespace Jellyfin.Server // ELSE IF $XDG_CONFIG_HOME use $XDG_CONFIG_HOME/jellyfin // ELSE $HOME/.config/jellyfin var configDir = options.ConfigDir; - if (string.IsNullOrEmpty(configDir)) { configDir = Environment.GetEnvironmentVariable("JELLYFIN_CONFIG_DIR"); @@ -294,7 +286,6 @@ namespace Jellyfin.Server // Ensure the main folders exist before we continue try { - Directory.CreateDirectory(dataDir); Directory.CreateDirectory(logDir); Directory.CreateDirectory(configDir); Directory.CreateDirectory(cacheDir); @@ -309,29 +300,33 @@ namespace Jellyfin.Server return new ServerApplicationPaths(dataDir, logDir, configDir, cacheDir); } - private static async Task CreateLogger(IApplicationPaths appPaths) + private static async Task<IConfiguration> CreateConfiguration(IApplicationPaths appPaths) { - try - { - string configPath = Path.Combine(appPaths.ConfigurationDirectoryPath, "logging.json"); + string configPath = Path.Combine(appPaths.ConfigurationDirectoryPath, "logging.json"); - if (!File.Exists(configPath)) + if (!File.Exists(configPath)) + { + // For some reason the csproj name is used instead of the assembly name + using (Stream rscstr = typeof(Program).Assembly + .GetManifestResourceStream("Jellyfin.Server.Resources.Configuration.logging.json")) + using (Stream fstr = File.Open(configPath, FileMode.CreateNew)) { - // For some reason the csproj name is used instead of the assembly name - using (Stream rscstr = typeof(Program).Assembly - .GetManifestResourceStream("Jellyfin.Server.Resources.Configuration.logging.json")) - using (Stream fstr = File.Open(configPath, FileMode.CreateNew)) - { - await rscstr.CopyToAsync(fstr).ConfigureAwait(false); - } + await rscstr.CopyToAsync(fstr).ConfigureAwait(false); } + } - var configuration = new ConfigurationBuilder() - .SetBasePath(appPaths.ConfigurationDirectoryPath) - .AddJsonFile("logging.json") - .AddEnvironmentVariables("JELLYFIN_") - .Build(); + return new ConfigurationBuilder() + .SetBasePath(appPaths.ConfigurationDirectoryPath) + .AddJsonFile("logging.json") + .AddEnvironmentVariables("JELLYFIN_") + .AddInMemoryCollection(ConfigurationOptions.Configuration) + .Build(); + } + private static void CreateLogger(IConfiguration configuration, IApplicationPaths appPaths) + { + try + { // Serilog.Log is used by SerilogLoggerFactory when no logger is specified Serilog.Log.Logger = new LoggerConfiguration() .ReadFrom.Configuration(configuration) |
