diff options
Diffstat (limited to 'Jellyfin.Server/Program.cs')
| -rw-r--r-- | Jellyfin.Server/Program.cs | 44 |
1 files changed, 17 insertions, 27 deletions
diff --git a/Jellyfin.Server/Program.cs b/Jellyfin.Server/Program.cs index cb763dfa3..7052f4d2b 100644 --- a/Jellyfin.Server/Program.cs +++ b/Jellyfin.Server/Program.cs @@ -1,11 +1,13 @@ using System; using System.Collections.Generic; using System.Diagnostics; +using System.Globalization; using System.IO; using System.Linq; using System.Net; using System.Reflection; using System.Runtime.InteropServices; +using System.Runtime.Versioning; using System.Text; using System.Threading; using System.Threading.Tasks; @@ -92,8 +94,7 @@ namespace Jellyfin.Server private static async Task StartApp(StartupOptions options) { - var stopWatch = new Stopwatch(); - stopWatch.Start(); + var startTimestamp = Stopwatch.GetTimestamp(); // Log all uncaught exceptions to std error static void UnhandledExceptionToConsole(object sender, UnhandledExceptionEventArgs e) => @@ -200,7 +201,7 @@ namespace Jellyfin.Server { await webHost.StartAsync(_tokenSource.Token).ConfigureAwait(false); - if (startupConfig.UseUnixSocket() && Environment.OSVersion.Platform == PlatformID.Unix) + if (!OperatingSystem.IsWindows() && startupConfig.UseUnixSocket()) { var socketPath = GetUnixSocketPath(startupConfig, appPaths); @@ -215,9 +216,7 @@ namespace Jellyfin.Server await appHost.RunStartupTasksAsync(_tokenSource.Token).ConfigureAwait(false); - stopWatch.Stop(); - - _logger.LogInformation("Startup complete {Time:g}", stopWatch.Elapsed); + _logger.LogInformation("Startup complete {Time:g}", Stopwatch.GetElapsedTime(startTimestamp)); // Block main thread until shutdown await Task.Delay(-1, _tokenSource.Token).ConfigureAwait(false); @@ -233,7 +232,7 @@ namespace Jellyfin.Server finally { // Don't throw additional exception if startup failed. - if (appHost.ServiceProvider != null) + if (appHost.ServiceProvider is not null) { _logger.LogInformation("Running query planner optimizations in the database... This might take a while"); // Run before disposing the application @@ -406,7 +405,7 @@ namespace Jellyfin.Server if (string.IsNullOrEmpty(configDir)) { - if (options.DataDir != null + if (options.DataDir is not null || Directory.Exists(Path.Combine(dataDir, "config")) || OperatingSystem.IsWindows()) { @@ -581,7 +580,7 @@ namespace Jellyfin.Server { // Use the swagger API page as the default redirect path if not hosting the web client var inMemoryDefaultConfig = ConfigurationOptions.DefaultConfiguration; - if (startupConfig != null && !startupConfig.HostWebClient()) + if (startupConfig is not null && !startupConfig.HostWebClient()) { inMemoryDefaultConfig[DefaultRedirectKey] = "api-docs/swagger"; } @@ -612,11 +611,14 @@ namespace Jellyfin.Server catch (Exception ex) { Log.Logger = new LoggerConfiguration() - .WriteTo.Console(outputTemplate: "[{Timestamp:HH:mm:ss}] [{Level:u3}] [{ThreadId}] {SourceContext}: {Message:lj}{NewLine}{Exception}") + .WriteTo.Console( + outputTemplate: "[{Timestamp:HH:mm:ss}] [{Level:u3}] [{ThreadId}] {SourceContext}: {Message:lj}{NewLine}{Exception}", + formatProvider: CultureInfo.InvariantCulture) .WriteTo.Async(x => x.File( Path.Combine(appPaths.LogDirectoryPath, "log_.log"), rollingInterval: RollingInterval.Day, outputTemplate: "[{Timestamp:yyyy-MM-dd HH:mm:ss.fff zzz}] [{Level:u3}] [{ThreadId}] {SourceContext}: {Message}{NewLine}{Exception}", + formatProvider: CultureInfo.InvariantCulture, encoding: Encoding.UTF8)) .Enrich.FromLogContext() .Enrich.WithThreadId() @@ -638,7 +640,7 @@ namespace Jellyfin.Server } string commandLineArgsString; - if (options.RestartArgs != null) + if (options.RestartArgs is not null) { commandLineArgsString = options.RestartArgs; } @@ -673,7 +675,7 @@ namespace Jellyfin.Server { var xdgRuntimeDir = Environment.GetEnvironmentVariable("XDG_RUNTIME_DIR"); var socketFile = "jellyfin.sock"; - if (xdgRuntimeDir == null) + if (xdgRuntimeDir is null) { // Fall back to config dir socketPath = Path.Join(appPaths.ConfigurationDirectoryPath, socketFile); @@ -687,27 +689,15 @@ namespace Jellyfin.Server return socketPath; } + [UnsupportedOSPlatform("windows")] private static void SetUnixSocketPermissions(IConfiguration startupConfig, string socketPath) { var socketPerms = startupConfig.GetUnixSocketPermissions(); if (!string.IsNullOrEmpty(socketPerms)) { - #pragma warning disable SA1300 // Entrypoint is case sensitive. - [DllImport("libc")] - static extern int chmod(string pathname, int mode); - #pragma warning restore SA1300 - - var exitCode = chmod(socketPath, Convert.ToInt32(socketPerms, 8)); - - if (exitCode < 0) - { - _logger.LogError("Failed to set Kestrel unix socket permissions to {SocketPerms}, return code: {ExitCode}", socketPerms, exitCode); - } - else - { - _logger.LogInformation("Kestrel unix socket permissions set to {SocketPerms}", socketPerms); - } + File.SetUnixFileMode(socketPath, (UnixFileMode)Convert.ToInt32(socketPerms, 8)); + _logger.LogInformation("Kestrel unix socket permissions set to {SocketPerms}", socketPerms); } } } |
