From cbe47325b328b70e5a49dc231a70d3709f71dbbd Mon Sep 17 00:00:00 2001 From: Bond_009 Date: Thu, 23 Jul 2020 13:18:47 +0200 Subject: [PATCH 1/4] Make UNIX socket configurable --- .../ConfigurationOptions.cs | 4 +-- Jellyfin.Server/Program.cs | 21 ++++++++++++--- .../Extensions/ConfigurationExtensions.cs | 26 +++++++++++++++++++ 3 files changed, 45 insertions(+), 6 deletions(-) diff --git a/Emby.Server.Implementations/ConfigurationOptions.cs b/Emby.Server.Implementations/ConfigurationOptions.cs index ff7ee085f..9a4693db0 100644 --- a/Emby.Server.Implementations/ConfigurationOptions.cs +++ b/Emby.Server.Implementations/ConfigurationOptions.cs @@ -1,6 +1,5 @@ using System.Collections.Generic; using Emby.Server.Implementations.HttpServer; -using Emby.Server.Implementations.Updates; using static MediaBrowser.Controller.Extensions.ConfigurationExtensions; namespace Emby.Server.Implementations @@ -19,7 +18,8 @@ namespace Emby.Server.Implementations { HttpListenerHost.DefaultRedirectKey, "web/index.html" }, { FfmpegProbeSizeKey, "1G" }, { FfmpegAnalyzeDurationKey, "200M" }, - { PlaylistsAllowDuplicatesKey, bool.TrueString } + { PlaylistsAllowDuplicatesKey, bool.TrueString }, + { BindToUnixSocketKey, bool.TrueString } }; } } diff --git a/Jellyfin.Server/Program.cs b/Jellyfin.Server/Program.cs index 444a91c02..f3ee339d1 100644 --- a/Jellyfin.Server/Program.cs +++ b/Jellyfin.Server/Program.cs @@ -344,11 +344,24 @@ namespace Jellyfin.Server } } - // Bind to unix socket (only on OSX and Linux) - if (!RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) + // Bind to unix socket (only on macOS and Linux) + if (startupConfig.UseUnixSocket() && !RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) { - // TODO: allow configuration of socket path - var socketPath = $"{appPaths.DataPath}/socket.sock"; + var socketPath = startupConfig.GetUnixSocketPath(); + if (string.IsNullOrEmpty(socketPath)) + { + var xdgRuntimeDir = Environment.GetEnvironmentVariable("XDG_RUNTIME_DIR"); + if (xdgRuntimeDir == null) + { + // Fall back to config dir + socketPath = Path.Join(appPaths.ConfigurationDirectoryPath, "socket.sock"); + } + else + { + socketPath = Path.Join(xdgRuntimeDir, "jellyfin-socket"); + } + } + // Workaround for https://github.com/aspnet/AspNetCore/issues/14134 if (File.Exists(socketPath)) { diff --git a/MediaBrowser.Controller/Extensions/ConfigurationExtensions.cs b/MediaBrowser.Controller/Extensions/ConfigurationExtensions.cs index c2932cc4c..ae02c1cee 100644 --- a/MediaBrowser.Controller/Extensions/ConfigurationExtensions.cs +++ b/MediaBrowser.Controller/Extensions/ConfigurationExtensions.cs @@ -33,6 +33,16 @@ namespace MediaBrowser.Controller.Extensions /// public const string PlaylistsAllowDuplicatesKey = "playlists:allowDuplicates"; + /// + /// The key for a setting that indicates whether kestrel should bind to a unix socket. + /// + public const string BindToUnixSocketKey = "kerstrel:socket"; + + /// + /// The key for the unix socket path. + /// + public const string UnixSocketPathKey = "kerstrel:socketPath"; + /// /// Gets a value indicating whether the application should host static web content from the . /// @@ -65,5 +75,21 @@ namespace MediaBrowser.Controller.Extensions /// True if playlists should allow duplicates, otherwise false. public static bool DoPlaylistsAllowDuplicates(this IConfiguration configuration) => configuration.GetValue(PlaylistsAllowDuplicatesKey); + + /// + /// Gets a value indicating whether kestrel should bind to a unix socket from the . + /// + /// The configuration to read the setting from. + /// true if kestrel should bind to a unix socket, otherwise false. + public static bool UseUnixSocket(this IConfiguration configuration) + => configuration.GetValue(BindToUnixSocketKey); + + /// + /// Gets the path for the unix socket from the . + /// + /// The configuration to read the setting from. + /// The unix socket path. + public static string GetUnixSocketPath(this IConfiguration configuration) + => configuration[FfmpegAnalyzeDurationKey]; } } From d006f4301a472038d1ee77c8c3b3c615b4a0f59a Mon Sep 17 00:00:00 2001 From: Bond_009 Date: Thu, 23 Jul 2020 13:20:10 +0200 Subject: [PATCH 2/4] Disable unix socket by default --- Emby.Server.Implementations/ConfigurationOptions.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Emby.Server.Implementations/ConfigurationOptions.cs b/Emby.Server.Implementations/ConfigurationOptions.cs index 9a4693db0..64ccff53b 100644 --- a/Emby.Server.Implementations/ConfigurationOptions.cs +++ b/Emby.Server.Implementations/ConfigurationOptions.cs @@ -19,7 +19,7 @@ namespace Emby.Server.Implementations { FfmpegProbeSizeKey, "1G" }, { FfmpegAnalyzeDurationKey, "200M" }, { PlaylistsAllowDuplicatesKey, bool.TrueString }, - { BindToUnixSocketKey, bool.TrueString } + { BindToUnixSocketKey, bool.FalseString } }; } } From 1cc62d6afa121607abf5c68a088de790f105f917 Mon Sep 17 00:00:00 2001 From: Bond-009 Date: Fri, 24 Jul 2020 09:36:18 +0200 Subject: [PATCH 3/4] Update MediaBrowser.Controller/Extensions/ConfigurationExtensions.cs Co-authored-by: David Mouse --- MediaBrowser.Controller/Extensions/ConfigurationExtensions.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/MediaBrowser.Controller/Extensions/ConfigurationExtensions.cs b/MediaBrowser.Controller/Extensions/ConfigurationExtensions.cs index ae02c1cee..425b39fd9 100644 --- a/MediaBrowser.Controller/Extensions/ConfigurationExtensions.cs +++ b/MediaBrowser.Controller/Extensions/ConfigurationExtensions.cs @@ -36,12 +36,12 @@ namespace MediaBrowser.Controller.Extensions /// /// The key for a setting that indicates whether kestrel should bind to a unix socket. /// - public const string BindToUnixSocketKey = "kerstrel:socket"; + public const string BindToUnixSocketKey = "kestrel:socket"; /// /// The key for the unix socket path. /// - public const string UnixSocketPathKey = "kerstrel:socketPath"; + public const string UnixSocketPathKey = "kestrel:socketPath"; /// /// Gets a value indicating whether the application should host static web content from the . From 6c92154a9bc78deeafa313c96c1fe474a5976776 Mon Sep 17 00:00:00 2001 From: Bond-009 Date: Sun, 9 Aug 2020 13:55:57 +0200 Subject: [PATCH 4/4] Update MediaBrowser.Controller/Extensions/ConfigurationExtensions.cs Co-authored-by: David --- MediaBrowser.Controller/Extensions/ConfigurationExtensions.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/MediaBrowser.Controller/Extensions/ConfigurationExtensions.cs b/MediaBrowser.Controller/Extensions/ConfigurationExtensions.cs index 425b39fd9..4c2209b67 100644 --- a/MediaBrowser.Controller/Extensions/ConfigurationExtensions.cs +++ b/MediaBrowser.Controller/Extensions/ConfigurationExtensions.cs @@ -90,6 +90,6 @@ namespace MediaBrowser.Controller.Extensions /// The configuration to read the setting from. /// The unix socket path. public static string GetUnixSocketPath(this IConfiguration configuration) - => configuration[FfmpegAnalyzeDurationKey]; + => configuration[UnixSocketPathKey]; } }