From 2850ff7b8afb2ab1a35c2797f88cef1bc0de8bd9 Mon Sep 17 00:00:00 2001 From: Bond_009 Date: Sat, 5 Jan 2019 19:12:05 +0100 Subject: [PATCH 1/3] Make config path configurable --- .../AppBase/BaseApplicationPaths.cs | 25 +++++++++++++++-- .../ServerApplicationPaths.cs | 9 ++++-- Jellyfin.Server/Program.cs | 28 ++++++++++++++++++- 3 files changed, 57 insertions(+), 5 deletions(-) diff --git a/Emby.Server.Implementations/AppBase/BaseApplicationPaths.cs b/Emby.Server.Implementations/AppBase/BaseApplicationPaths.cs index 76d0076a66..3e12bc0b6e 100644 --- a/Emby.Server.Implementations/AppBase/BaseApplicationPaths.cs +++ b/Emby.Server.Implementations/AppBase/BaseApplicationPaths.cs @@ -12,11 +12,16 @@ namespace Emby.Server.Implementations.AppBase /// /// Initializes a new instance of the class. /// - protected BaseApplicationPaths(string programDataPath, string appFolderPath, string logDirectoryPath) + protected BaseApplicationPaths( + string programDataPath, + string appFolderPath, + string logDirectoryPath = null, + string configurationDirectoryPath = null) { ProgramDataPath = programDataPath; ProgramSystemPath = appFolderPath; LogDirectoryPath = logDirectoryPath; + ConfigurationDirectoryPath = configurationDirectoryPath; } public string ProgramDataPath { get; private set; } @@ -134,6 +139,11 @@ namespace Emby.Server.Implementations.AppBase } } + /// + /// The _config directory + /// + private string _configurationDirectoryPath; + /// /// Gets the path to the application configuration root directory /// @@ -142,7 +152,18 @@ namespace Emby.Server.Implementations.AppBase { get { - return Path.Combine(ProgramDataPath, "config"); + if (string.IsNullOrEmpty(_configurationDirectoryPath)) + { + _configurationDirectoryPath = Path.Combine(ProgramDataPath, "config"); + + Directory.CreateDirectory(_configurationDirectoryPath); + } + + return _configurationDirectoryPath; + } + set + { + _configurationDirectoryPath = value; } } diff --git a/Emby.Server.Implementations/ServerApplicationPaths.cs b/Emby.Server.Implementations/ServerApplicationPaths.cs index f5986f9433..8a0f2671ac 100644 --- a/Emby.Server.Implementations/ServerApplicationPaths.cs +++ b/Emby.Server.Implementations/ServerApplicationPaths.cs @@ -13,8 +13,13 @@ namespace Emby.Server.Implementations /// /// Initializes a new instance of the class. /// - public ServerApplicationPaths(string programDataPath, string appFolderPath, string applicationResourcesPath, string logDirectoryPath = null) - : base(programDataPath, appFolderPath, logDirectoryPath) + public ServerApplicationPaths( + string programDataPath, + string appFolderPath, + string applicationResourcesPath, + string logDirectoryPath = null, + string configurationDirectoryPath = null) + : base(programDataPath, appFolderPath, logDirectoryPath, configurationDirectoryPath) { ApplicationResourcesPath = applicationResourcesPath; } diff --git a/Jellyfin.Server/Program.cs b/Jellyfin.Server/Program.cs index 2dd4d9af66..d8a7463043 100644 --- a/Jellyfin.Server/Program.cs +++ b/Jellyfin.Server/Program.cs @@ -124,6 +124,32 @@ namespace Jellyfin.Server } } programDataPath = Path.Combine(programDataPath, "jellyfin"); + Directory.CreateDirectory(programDataPath); + } + + string configPath; + if (options.ContainsOption("-configpath")) + { + configPath = options.GetOption("-configpath"); + } + else + { + if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) + { + configPath = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData); + } + else + { + // $XDG_CONFIG_HOME defines the base directory relative to which user specific configuration files should be stored. + configPath = Environment.GetEnvironmentVariable("XDG_CONFIG_HOME"); + // If $XDG_CONFIG_HOME is either not set or empty, $HOME/.config should be used. + if (string.IsNullOrEmpty(configPath)) + { + configPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile), ".local", "share"); + } + } + configPath = Path.Combine(configPath, "jellyfin"); + Directory.CreateDirectory(configPath); } string logDir = Environment.GetEnvironmentVariable("JELLYFIN_LOG_DIR"); @@ -138,7 +164,7 @@ namespace Jellyfin.Server string appPath = AppContext.BaseDirectory; - return new ServerApplicationPaths(programDataPath, appPath, appPath, logDir); + return new ServerApplicationPaths(programDataPath, appPath, appPath, logDir, configPath); } private static async Task createLogger(IApplicationPaths appPaths) From 23267bb08f7dcc319c81cdbdaa68efb0c6ea5bc7 Mon Sep 17 00:00:00 2001 From: Bond_009 Date: Sat, 5 Jan 2019 21:11:55 +0100 Subject: [PATCH 2/3] Use -logdir if env var isn't set --- Jellyfin.Server/Program.cs | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/Jellyfin.Server/Program.cs b/Jellyfin.Server/Program.cs index d8a7463043..53eaacad09 100644 --- a/Jellyfin.Server/Program.cs +++ b/Jellyfin.Server/Program.cs @@ -124,13 +124,14 @@ namespace Jellyfin.Server } } programDataPath = Path.Combine(programDataPath, "jellyfin"); + // Ensure the dir exists Directory.CreateDirectory(programDataPath); } string configPath; - if (options.ContainsOption("-configpath")) + if (options.ContainsOption("-configdir")) { - configPath = options.GetOption("-configpath"); + configPath = options.GetOption("-configdir"); } else { @@ -149,15 +150,23 @@ namespace Jellyfin.Server } } configPath = Path.Combine(configPath, "jellyfin"); + // Ensure the dir exists Directory.CreateDirectory(configPath); } string logDir = Environment.GetEnvironmentVariable("JELLYFIN_LOG_DIR"); if (string.IsNullOrEmpty(logDir)) { - logDir = Path.Combine(programDataPath, "logs"); - // Ensure logDir exists - Directory.CreateDirectory(logDir); + if (options.ContainsOption("-logdir")) + { + logDir = options.GetOption("-logdir"); + } + else + { + logDir = Path.Combine(programDataPath, "logs"); + // Ensure the dir exists + Directory.CreateDirectory(logDir); + } // $JELLYFIN_LOG_DIR needs to be set for the logger configuration manager Environment.SetEnvironmentVariable("JELLYFIN_LOG_DIR", logDir); } From f6d50c411f0008497f95e6e7e31eb7f04eb2c360 Mon Sep 17 00:00:00 2001 From: Bond_009 Date: Sat, 5 Jan 2019 21:16:47 +0100 Subject: [PATCH 3/3] Add env vars JELLYFIN_CONFIG_DIR and JELLYFIN_DATA_PATH --- Jellyfin.Server/Program.cs | 72 +++++++++++++++++++++----------------- 1 file changed, 39 insertions(+), 33 deletions(-) diff --git a/Jellyfin.Server/Program.cs b/Jellyfin.Server/Program.cs index 53eaacad09..eedc9f9ce6 100644 --- a/Jellyfin.Server/Program.cs +++ b/Jellyfin.Server/Program.cs @@ -102,56 +102,62 @@ namespace Jellyfin.Server private static ServerApplicationPaths createApplicationPaths(StartupOptions options) { - string programDataPath; - if (options.ContainsOption("-programdata")) + string programDataPath = Environment.GetEnvironmentVariable("JELLYFIN_DATA_PATH"); + if (string.IsNullOrEmpty(programDataPath)) { - programDataPath = options.GetOption("-programdata"); - } - else - { - if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) + if (options.ContainsOption("-programdata")) { - programDataPath = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData); + programDataPath = options.GetOption("-programdata"); } else { - // $XDG_DATA_HOME defines the base directory relative to which user specific data files should be stored. - programDataPath = Environment.GetEnvironmentVariable("XDG_DATA_HOME"); - // If $XDG_DATA_HOME is either not set or empty, $HOME/.local/share should be used. - if (string.IsNullOrEmpty(programDataPath)) + if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) { - programDataPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile), ".local", "share"); + programDataPath = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData); } + else + { + // $XDG_DATA_HOME defines the base directory relative to which user specific data files should be stored. + programDataPath = Environment.GetEnvironmentVariable("XDG_DATA_HOME"); + // If $XDG_DATA_HOME is either not set or empty, $HOME/.local/share should be used. + if (string.IsNullOrEmpty(programDataPath)) + { + programDataPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile), ".local", "share"); + } + } + programDataPath = Path.Combine(programDataPath, "jellyfin"); + // Ensure the dir exists + Directory.CreateDirectory(programDataPath); } - programDataPath = Path.Combine(programDataPath, "jellyfin"); - // Ensure the dir exists - Directory.CreateDirectory(programDataPath); } - string configPath; - if (options.ContainsOption("-configdir")) + string configDir = Environment.GetEnvironmentVariable("JELLYFIN_CONFIG_DIR"); + if (string.IsNullOrEmpty(configDir)) { - configPath = options.GetOption("-configdir"); - } - else - { - if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) + if (options.ContainsOption("-configdir")) { - configPath = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData); + configDir = options.GetOption("-configdir"); } else { - // $XDG_CONFIG_HOME defines the base directory relative to which user specific configuration files should be stored. - configPath = Environment.GetEnvironmentVariable("XDG_CONFIG_HOME"); - // If $XDG_CONFIG_HOME is either not set or empty, $HOME/.config should be used. - if (string.IsNullOrEmpty(configPath)) + if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) { - configPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile), ".local", "share"); + configDir = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData); } + else + { + // $XDG_CONFIG_HOME defines the base directory relative to which user specific configuration files should be stored. + configDir = Environment.GetEnvironmentVariable("XDG_CONFIG_HOME"); + // If $XDG_CONFIG_HOME is either not set or empty, $HOME/.config should be used. + if (string.IsNullOrEmpty(configDir)) + { + configDir = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile), ".local", "share"); + } + } + configDir = Path.Combine(configDir, "jellyfin"); + // Ensure the dir exists + Directory.CreateDirectory(configDir); } - configPath = Path.Combine(configPath, "jellyfin"); - // Ensure the dir exists - Directory.CreateDirectory(configPath); } string logDir = Environment.GetEnvironmentVariable("JELLYFIN_LOG_DIR"); @@ -173,7 +179,7 @@ namespace Jellyfin.Server string appPath = AppContext.BaseDirectory; - return new ServerApplicationPaths(programDataPath, appPath, appPath, logDir, configPath); + return new ServerApplicationPaths(programDataPath, appPath, appPath, logDir, configDir); } private static async Task createLogger(IApplicationPaths appPaths)