diff --git a/Jellyfin.Server/HealthChecks/JellyfinDbHealthCheck.cs b/Jellyfin.Server/HealthChecks/JellyfinDbHealthCheck.cs
new file mode 100644
index 0000000000..aea6844798
--- /dev/null
+++ b/Jellyfin.Server/HealthChecks/JellyfinDbHealthCheck.cs
@@ -0,0 +1,36 @@
+using System.Threading;
+using System.Threading.Tasks;
+using Jellyfin.Server.Implementations;
+using Microsoft.Extensions.Diagnostics.HealthChecks;
+
+namespace Jellyfin.Server.HealthChecks
+{
+ ///
+ /// Checks connectivity to the database.
+ ///
+ public class JellyfinDbHealthCheck : IHealthCheck
+ {
+ private readonly JellyfinDbProvider _dbProvider;
+
+ ///
+ /// Initializes a new instance of the class.
+ ///
+ /// The jellyfin db provider.
+ public JellyfinDbHealthCheck(JellyfinDbProvider dbProvider)
+ {
+ _dbProvider = dbProvider;
+ }
+
+ ///
+ public async Task CheckHealthAsync(HealthCheckContext context, CancellationToken cancellationToken = default)
+ {
+ await using var jellyfinDb = _dbProvider.CreateContext();
+ if (await jellyfinDb.Database.CanConnectAsync(cancellationToken).ConfigureAwait(false))
+ {
+ return HealthCheckResult.Healthy("Database connection successful.");
+ }
+
+ return HealthCheckResult.Unhealthy("Unable to connect to the database.");
+ }
+ }
+}
diff --git a/Jellyfin.Server/Jellyfin.Server.csproj b/Jellyfin.Server/Jellyfin.Server.csproj
index 7541707d9f..6ea7e84de0 100644
--- a/Jellyfin.Server/Jellyfin.Server.csproj
+++ b/Jellyfin.Server/Jellyfin.Server.csproj
@@ -43,6 +43,7 @@
+
diff --git a/Jellyfin.Server/Startup.cs b/Jellyfin.Server/Startup.cs
index 995271aa32..08d59543aa 100644
--- a/Jellyfin.Server/Startup.cs
+++ b/Jellyfin.Server/Startup.cs
@@ -1,11 +1,12 @@
using System;
using System.ComponentModel;
+using System.Data.OleDb;
using System.Net.Http.Headers;
using Jellyfin.Api.TypeConverters;
using Jellyfin.Server.Extensions;
+using Jellyfin.Server.HealthChecks;
using Jellyfin.Server.Middleware;
using Jellyfin.Server.Models;
-using MediaBrowser.Common;
using MediaBrowser.Common.Net;
using MediaBrowser.Controller;
using MediaBrowser.Controller.Configuration;
@@ -77,6 +78,9 @@ namespace Jellyfin.Server
c.DefaultRequestHeaders.UserAgent.Add(new ProductInfoHeaderValue($"({_serverApplicationHost.ApplicationUserAgentAddress})"));
})
.ConfigurePrimaryHttpMessageHandler(x => new DefaultHttpClientHandler());
+
+ services.AddHealthChecks()
+ .AddCheck("JellyfinDb");
}
///
@@ -132,6 +136,8 @@ namespace Jellyfin.Server
{
endpoints.MapMetrics(_serverConfigurationManager.Configuration.BaseUrl.TrimStart('/') + "/metrics");
}
+
+ endpoints.MapHealthChecks(_serverConfigurationManager.Configuration.BaseUrl.TrimStart('/') + "/health");
});
// Add type descriptor for legacy datetime parsing.