aboutsummaryrefslogtreecommitdiff
path: root/Jellyfin.Server
diff options
context:
space:
mode:
Diffstat (limited to 'Jellyfin.Server')
-rw-r--r--Jellyfin.Server/Helpers/StartupHelpers.cs211
-rw-r--r--Jellyfin.Server/Jellyfin.Server.csproj38
-rw-r--r--Jellyfin.Server/Program.cs2
-rw-r--r--Jellyfin.Server/Startup.cs3
4 files changed, 116 insertions, 138 deletions
diff --git a/Jellyfin.Server/Helpers/StartupHelpers.cs b/Jellyfin.Server/Helpers/StartupHelpers.cs
index f1bb9b283..fda6e5465 100644
--- a/Jellyfin.Server/Helpers/StartupHelpers.cs
+++ b/Jellyfin.Server/Helpers/StartupHelpers.cs
@@ -1,7 +1,10 @@
using System;
+using System.Collections.Generic;
using System.Globalization;
using System.IO;
+using System.Linq;
using System.Net;
+using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using System.Text;
using System.Threading.Tasks;
@@ -22,6 +25,43 @@ namespace Jellyfin.Server.Helpers;
/// </summary>
public static class StartupHelpers
{
+ private static readonly string[] _relevantEnvVarPrefixes = { "JELLYFIN_", "DOTNET_", "ASPNETCORE_" };
+
+ /// <summary>
+ /// Logs relevant environment variables and information about the host.
+ /// </summary>
+ /// <param name="logger">The logger to use.</param>
+ /// <param name="appPaths">The application paths to use.</param>
+ public static void LogEnvironmentInfo(ILogger logger, IApplicationPaths appPaths)
+ {
+ // Distinct these to prevent users from reporting problems that aren't actually problems
+ var commandLineArgs = Environment
+ .GetCommandLineArgs()
+ .Distinct();
+
+ // Get all relevant environment variables
+ var allEnvVars = Environment.GetEnvironmentVariables();
+ var relevantEnvVars = new Dictionary<object, object>();
+ foreach (var key in allEnvVars.Keys)
+ {
+ if (_relevantEnvVarPrefixes.Any(prefix => key.ToString()!.StartsWith(prefix, StringComparison.OrdinalIgnoreCase)))
+ {
+ relevantEnvVars.Add(key, allEnvVars[key]!);
+ }
+ }
+
+ logger.LogInformation("Environment Variables: {EnvVars}", relevantEnvVars);
+ logger.LogInformation("Arguments: {Args}", commandLineArgs);
+ logger.LogInformation("Operating system: {OS}", RuntimeInformation.OSDescription);
+ logger.LogInformation("Architecture: {Architecture}", RuntimeInformation.OSArchitecture);
+ logger.LogInformation("64-Bit Process: {Is64Bit}", Environment.Is64BitProcess);
+ logger.LogInformation("User Interactive: {IsUserInteractive}", Environment.UserInteractive);
+ logger.LogInformation("Processor count: {ProcessorCount}", Environment.ProcessorCount);
+ logger.LogInformation("Program data path: {ProgramDataPath}", appPaths.ProgramDataPath);
+ logger.LogInformation("Web resources path: {WebPath}", appPaths.WebPath);
+ logger.LogInformation("Application directory: {ApplicationPath}", appPaths.ProgramSystemPath);
+ }
+
/// <summary>
/// Create the data, config and log paths from the variety of inputs(command line args,
/// environment variables) or decide on what default to use. For Windows it's %AppPath%
@@ -33,137 +73,55 @@ public static class StartupHelpers
/// <returns><see cref="ServerApplicationPaths" />.</returns>
public static ServerApplicationPaths CreateApplicationPaths(StartupOptions options)
{
- // dataDir
- // IF --datadir
- // ELSE IF $JELLYFIN_DATA_DIR
- // ELSE IF windows, use <%APPDATA%>/jellyfin
- // ELSE IF $XDG_DATA_HOME then use $XDG_DATA_HOME/jellyfin
- // ELSE use $HOME/.local/share/jellyfin
- var dataDir = options.DataDir;
- if (string.IsNullOrEmpty(dataDir))
- {
- dataDir = Environment.GetEnvironmentVariable("JELLYFIN_DATA_DIR");
+ // LocalApplicationData
+ // Windows: %LocalAppData%
+ // macOS: NSApplicationSupportDirectory
+ // UNIX: $XDG_DATA_HOME
+ var dataDir = options.DataDir
+ ?? Environment.GetEnvironmentVariable("JELLYFIN_DATA_DIR")
+ ?? Path.Join(
+ Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData),
+ "jellyfin");
- if (string.IsNullOrEmpty(dataDir))
+ var configDir = options.ConfigDir ?? Environment.GetEnvironmentVariable("JELLYFIN_CONFIG_DIR");
+ if (configDir is null)
+ {
+ configDir = Path.Join(dataDir, "config");
+ if (options.DataDir is null
+ && !Directory.Exists(configDir)
+ && !OperatingSystem.IsWindows()
+ && !OperatingSystem.IsMacOS())
{
- // LocalApplicationData follows the XDG spec on unix machines
- dataDir = Path.Combine(
- Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData),
+ // UNIX: $XDG_CONFIG_HOME
+ configDir = Path.Join(
+ Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData),
"jellyfin");
}
}
- // configDir
- // IF --configdir
- // ELSE IF $JELLYFIN_CONFIG_DIR
- // ELSE IF --datadir, use <datadir>/config (assume portable run)
- // ELSE IF <datadir>/config exists, use that
- // ELSE IF windows, use <datadir>/config
- // ELSE IF $XDG_CONFIG_HOME use $XDG_CONFIG_HOME/jellyfin
- // ELSE $HOME/.config/jellyfin
- var configDir = options.ConfigDir;
- if (string.IsNullOrEmpty(configDir))
+ var cacheDir = options.CacheDir ?? Environment.GetEnvironmentVariable("JELLYFIN_CACHE_DIR");
+ if (cacheDir is null)
{
- configDir = Environment.GetEnvironmentVariable("JELLYFIN_CONFIG_DIR");
-
- if (string.IsNullOrEmpty(configDir))
+ if (OperatingSystem.IsWindows() || OperatingSystem.IsMacOS())
{
- if (options.DataDir is not null
- || Directory.Exists(Path.Combine(dataDir, "config"))
- || OperatingSystem.IsWindows())
- {
- // Hang config folder off already set dataDir
- configDir = Path.Combine(dataDir, "config");
- }
- 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,
- // a default equal to $HOME /.config should be used.
- if (string.IsNullOrEmpty(configDir))
- {
- configDir = Path.Combine(
- Environment.GetFolderPath(Environment.SpecialFolder.UserProfile),
- ".config");
- }
-
- configDir = Path.Combine(configDir, "jellyfin");
- }
+ cacheDir = Path.Join(dataDir, "cache");
}
- }
-
- // cacheDir
- // IF --cachedir
- // ELSE IF $JELLYFIN_CACHE_DIR
- // ELSE IF windows, use <datadir>/cache
- // ELSE IF XDG_CACHE_HOME, use $XDG_CACHE_HOME/jellyfin
- // ELSE HOME/.cache/jellyfin
- var cacheDir = options.CacheDir;
- if (string.IsNullOrEmpty(cacheDir))
- {
- cacheDir = Environment.GetEnvironmentVariable("JELLYFIN_CACHE_DIR");
-
- if (string.IsNullOrEmpty(cacheDir))
+ else
{
- if (OperatingSystem.IsWindows())
- {
- // Hang cache folder off already set dataDir
- cacheDir = Path.Combine(dataDir, "cache");
- }
- else
- {
- // $XDG_CACHE_HOME defines the base directory relative to which
- // user specific non-essential data files should be stored.
- cacheDir = Environment.GetEnvironmentVariable("XDG_CACHE_HOME");
-
- // If $XDG_CACHE_HOME is either not set or empty,
- // a default equal to $HOME/.cache should be used.
- if (string.IsNullOrEmpty(cacheDir))
- {
- cacheDir = Path.Combine(
- Environment.GetFolderPath(Environment.SpecialFolder.UserProfile),
- ".cache");
- }
-
- cacheDir = Path.Combine(cacheDir, "jellyfin");
- }
+ cacheDir = Path.Join(GetXdgCacheHome(), "jellyfin");
}
}
- // webDir
- // IF --webdir
- // ELSE IF $JELLYFIN_WEB_DIR
- // ELSE <bindir>/jellyfin-web
- var webDir = options.WebDir;
- if (string.IsNullOrEmpty(webDir))
+ var webDir = options.WebDir ?? Environment.GetEnvironmentVariable("JELLYFIN_WEB_DIR");
+ if (webDir is null)
{
- webDir = Environment.GetEnvironmentVariable("JELLYFIN_WEB_DIR");
-
- if (string.IsNullOrEmpty(webDir))
- {
- // Use default location under ResourcesPath
- webDir = Path.Combine(AppContext.BaseDirectory, "jellyfin-web");
- }
+ webDir = Path.Join(AppContext.BaseDirectory, "jellyfin-web");
}
- // logDir
- // IF --logdir
- // ELSE IF $JELLYFIN_LOG_DIR
- // ELSE IF --datadir, use <datadir>/log (assume portable run)
- // ELSE <datadir>/log
- var logDir = options.LogDir;
- if (string.IsNullOrEmpty(logDir))
+ var logDir = options.LogDir ?? Environment.GetEnvironmentVariable("JELLYFIN_LOG_DIR");
+ if (logDir is null)
{
- logDir = Environment.GetEnvironmentVariable("JELLYFIN_LOG_DIR");
-
- if (string.IsNullOrEmpty(logDir))
- {
- // Hang log folder off already set dataDir
- logDir = Path.Combine(dataDir, "log");
- }
+ logDir = Path.Join(dataDir, "log");
}
// Normalize paths. Only possible with GetFullPath for now - https://github.com/dotnet/runtime/issues/2162
@@ -191,6 +149,24 @@ public static class StartupHelpers
return new ServerApplicationPaths(dataDir, logDir, configDir, cacheDir, webDir);
}
+ private static string GetXdgCacheHome()
+ {
+ // $XDG_CACHE_HOME defines the base directory relative to which
+ // user specific non-essential data files should be stored.
+ var cacheHome = Environment.GetEnvironmentVariable("XDG_CACHE_HOME");
+
+ // If $XDG_CACHE_HOME is either not set or a relative path,
+ // a default equal to $HOME/.cache should be used.
+ if (cacheHome is null || !cacheHome.StartsWith('/'))
+ {
+ cacheHome = Path.Join(
+ Environment.GetFolderPath(Environment.SpecialFolder.UserProfile),
+ ".cache");
+ }
+
+ return cacheHome;
+ }
+
/// <summary>
/// Gets the path for the unix socket Kestrel should bind to.
/// </summary>
@@ -203,16 +179,17 @@ public static class StartupHelpers
if (string.IsNullOrEmpty(socketPath))
{
+ const string SocketFile = "jellyfin.sock";
+
var xdgRuntimeDir = Environment.GetEnvironmentVariable("XDG_RUNTIME_DIR");
- var socketFile = "jellyfin.sock";
if (xdgRuntimeDir is null)
{
// Fall back to config dir
- socketPath = Path.Join(appPaths.ConfigurationDirectoryPath, socketFile);
+ socketPath = Path.Join(appPaths.ConfigurationDirectoryPath, SocketFile);
}
else
{
- socketPath = Path.Join(xdgRuntimeDir, socketFile);
+ socketPath = Path.Join(xdgRuntimeDir, SocketFile);
}
}
diff --git a/Jellyfin.Server/Jellyfin.Server.csproj b/Jellyfin.Server/Jellyfin.Server.csproj
index 9ea8508f2..146de3ae1 100644
--- a/Jellyfin.Server/Jellyfin.Server.csproj
+++ b/Jellyfin.Server/Jellyfin.Server.csproj
@@ -24,31 +24,31 @@
<!-- Code Analyzers-->
<ItemGroup Condition=" '$(Configuration)' == 'Debug' ">
- <PackageReference Include="Microsoft.CodeAnalysis.BannedApiAnalyzers" Version="3.3.4">
+ <PackageReference Include="Microsoft.CodeAnalysis.BannedApiAnalyzers">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
</PackageReference>
- <PackageReference Include="SerilogAnalyzer" Version="0.15.0" PrivateAssets="All" />
- <PackageReference Include="StyleCop.Analyzers" Version="1.2.0-beta.435" PrivateAssets="All" />
- <PackageReference Include="SmartAnalyzers.MultithreadingAnalyzer" Version="1.1.31" PrivateAssets="All" />
+ <PackageReference Include="SerilogAnalyzer" PrivateAssets="All" />
+ <PackageReference Include="StyleCop.Analyzers" PrivateAssets="All" />
+ <PackageReference Include="SmartAnalyzers.MultithreadingAnalyzer" PrivateAssets="All" />
</ItemGroup>
<ItemGroup>
- <PackageReference Include="CommandLineParser" Version="2.9.1" />
- <PackageReference Include="Microsoft.Extensions.Configuration.EnvironmentVariables" Version="7.0.0" />
- <PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="7.0.0" />
- <PackageReference Include="Microsoft.Extensions.Diagnostics.HealthChecks" Version="7.0.2" />
- <PackageReference Include="Microsoft.Extensions.Diagnostics.HealthChecks.EntityFrameworkCore" Version="7.0.2" />
- <PackageReference Include="prometheus-net" Version="7.0.0" />
- <PackageReference Include="prometheus-net.AspNetCore" Version="7.0.0" />
- <PackageReference Include="Serilog.AspNetCore" Version="6.1.0" />
- <PackageReference Include="Serilog.Enrichers.Thread" Version="3.1.0" />
- <PackageReference Include="Serilog.Settings.Configuration" Version="3.4.0" />
- <PackageReference Include="Serilog.Sinks.Async" Version="1.5.0" />
- <PackageReference Include="Serilog.Sinks.Console" Version="4.1.0" />
- <PackageReference Include="Serilog.Sinks.File" Version="5.0.0" />
- <PackageReference Include="Serilog.Sinks.Graylog" Version="2.3.0" />
- <PackageReference Include="SQLitePCLRaw.bundle_e_sqlite3" Version="2.1.4" />
+ <PackageReference Include="CommandLineParser" />
+ <PackageReference Include="Microsoft.Extensions.Configuration.EnvironmentVariables" />
+ <PackageReference Include="Microsoft.Extensions.Configuration.Json" />
+ <PackageReference Include="Microsoft.Extensions.Diagnostics.HealthChecks" />
+ <PackageReference Include="Microsoft.Extensions.Diagnostics.HealthChecks.EntityFrameworkCore" />
+ <PackageReference Include="prometheus-net" />
+ <PackageReference Include="prometheus-net.AspNetCore" />
+ <PackageReference Include="Serilog.AspNetCore" />
+ <PackageReference Include="Serilog.Enrichers.Thread" />
+ <PackageReference Include="Serilog.Settings.Configuration" />
+ <PackageReference Include="Serilog.Sinks.Async" />
+ <PackageReference Include="Serilog.Sinks.Console" />
+ <PackageReference Include="Serilog.Sinks.File" />
+ <PackageReference Include="Serilog.Sinks.Graylog" />
+ <PackageReference Include="SQLitePCLRaw.bundle_e_sqlite3" />
</ItemGroup>
<ItemGroup>
diff --git a/Jellyfin.Server/Program.cs b/Jellyfin.Server/Program.cs
index 25fe30a39..6e8b17a73 100644
--- a/Jellyfin.Server/Program.cs
+++ b/Jellyfin.Server/Program.cs
@@ -148,7 +148,7 @@ namespace Jellyfin.Server
"Jellyfin version: {Version}",
Assembly.GetEntryAssembly()!.GetName().Version!.ToString(3));
- ApplicationHost.LogEnvironmentInfo(_logger, appPaths);
+ StartupHelpers.LogEnvironmentInfo(_logger, appPaths);
// If hosting the web client, validate the client content path
if (startupConfig.HostWebClient())
diff --git a/Jellyfin.Server/Startup.cs b/Jellyfin.Server/Startup.cs
index 7abd2fbef..155f9fc8c 100644
--- a/Jellyfin.Server/Startup.cs
+++ b/Jellyfin.Server/Startup.cs
@@ -4,6 +4,7 @@ using System.Net;
using System.Net.Http;
using System.Net.Http.Headers;
using System.Net.Mime;
+using System.Runtime.InteropServices;
using System.Text;
using Jellyfin.Api.Middleware;
using Jellyfin.MediaEncoding.Hls.Extensions;
@@ -108,7 +109,7 @@ namespace Jellyfin.Server
string.Format(
CultureInfo.InvariantCulture,
"{0}/{1} UPnP/1.0 {2}/{3}",
- MediaBrowser.Common.System.OperatingSystem.Name,
+ Environment.OSVersion.Platform,
Environment.OSVersion,
_serverApplicationHost.Name,
_serverApplicationHost.ApplicationVersionString));