aboutsummaryrefslogtreecommitdiff
path: root/Jellyfin.Server/Program.cs
diff options
context:
space:
mode:
Diffstat (limited to 'Jellyfin.Server/Program.cs')
-rw-r--r--Jellyfin.Server/Program.cs25
1 files changed, 20 insertions, 5 deletions
diff --git a/Jellyfin.Server/Program.cs b/Jellyfin.Server/Program.cs
index 35eaff6532..29c7d512d0 100644
--- a/Jellyfin.Server/Program.cs
+++ b/Jellyfin.Server/Program.cs
@@ -149,8 +149,16 @@ namespace Jellyfin.Server
if (_restartOnShutdown)
{
_startTimestamp = Stopwatch.GetTimestamp();
- await _setupServer.StopAsync().ConfigureAwait(false);
- await _setupServer.RunAsync().ConfigureAwait(false);
+ try
+ {
+ await _setupServer.StopAsync().ConfigureAwait(false);
+ await _setupServer.RunAsync().ConfigureAwait(false);
+ }
+ catch (Exception ex)
+ {
+ // The startup page is optional, losing it must not take the restart down with it.
+ _logger.LogError(ex, "Failed to bring the startup server back up");
+ }
}
} while (_restartOnShutdown);
@@ -245,7 +253,15 @@ namespace Jellyfin.Server
await appHost.RunStartupTasksAsync().ConfigureAwait(false);
_logger.LogInformation("Startup complete {Time:g}", Stopwatch.GetElapsedTime(_startTimestamp));
- await _jellyfinHost.WaitForShutdownAsync().ConfigureAwait(false);
+ try
+ {
+ await _jellyfinHost.WaitForShutdownAsync().ConfigureAwait(false);
+ }
+ catch (Exception ex)
+ {
+ // A hosted service that throws or times out while stopping must not cancel a pending restart.
+ _logger.LogError(ex, "Failure while stopping the server");
+ }
}
_restartOnShutdown = appHost.ShouldRestart;
@@ -271,9 +287,8 @@ namespace Jellyfin.Server
// Don't throw additional exception if startup failed.
if (appHost.ServiceProvider is not null)
{
- _logger.LogInformation("Optimizing the database... This might take a while");
+ _logger.LogInformation("Preparing the database for shutdown...");
- // Deliberately untimed: a truncated optimization leaves the statistics incomplete.
var databaseProvider = appHost.ServiceProvider.GetRequiredService<IJellyfinDatabaseProvider>();
await databaseProvider.RunShutdownTask(CancellationToken.None).ConfigureAwait(false);
}