Skip to content

Usenet streaming with a WebDAV server and a SABnzbd-compatible API

C#

Wait for backend to start before starting frontend.

nzbdav-dev5eb9988f1322
diff --git a/Dockerfile b/Dockerfile
index 34afd9c1..c33610ec 100644
--- a/Dockerfile
+++ b/Dockerfile
@@ -28,7 +28,7 @@ WORKDIR /app
# Prepare environment
RUN mkdir /config \
- && apk add --no-cache nodejs npm libc6-compat shadow su-exec bash
+ && apk add --no-cache nodejs npm libc6-compat shadow su-exec bash curl
# Copy frontend
COPY --from=frontend-build /frontend/node_modules ./frontend/node_modules
diff --git a/backend/Extensions/NWebDavOptionsExtensions.cs b/backend/Extensions/NWebDavOptionsExtensions.cs
index 1fd7bb44..3c4b6c70 100644
--- a/backend/Extensions/NWebDavOptionsExtensions.cs
+++ b/backend/Extensions/NWebDavOptionsExtensions.cs
@@ -8,6 +8,7 @@ public static class NWebDavOptionsExtensions
public static Func<HttpContext, bool> GetFilter(this NWebDavOptions options)
{
return context => !context.Request.Path.StartsWithSegments("/api") &&
- !context.Request.Path.StartsWithSegments("/view");
+ !context.Request.Path.StartsWithSegments("/view") &&
+ !context.Request.Path.StartsWithSegments("/health");
}
}
\ No newline at end of file
diff --git a/backend/Program.cs b/backend/Program.cs
index fe3741d9..1d6bc006 100644
--- a/backend/Program.cs
+++ b/backend/Program.cs
@@ -51,6 +51,7 @@ class Program
var builder = WebApplication.CreateBuilder(args);
builder.Host.UseSerilog();
builder.Services.AddControllers();
+ builder.Services.AddHealthChecks();
builder.Services
.AddSingleton(configManager)
.AddSingleton<UsenetStreamingClient>()
@@ -85,6 +86,7 @@ class Program
// run
var app = builder.Build();
+ app.MapHealthChecks("/health");
app.UseSerilogRequestLogging();
app.UseMiddleware<ExceptionMiddleware>();
app.UseAuthentication();
diff --git a/entrypoint.sh b/entrypoint.sh
index 06800c62..3f042b26 100644
--- a/entrypoint.sh
+++ b/entrypoint.sh
@@ -54,6 +54,29 @@ cd /app/backend
su-exec appuser ./NzbWebDAV &
BACKEND_PID=$!
+# Wait for backend health check
+echo "Waiting for backend to start."
+MAX_RETRIES=30
+RETRY_DELAY=1
+i=0
+while true; do
+ echo "Checking backend health: $BACKEND_URL/health ..."
+ if curl -s -o /dev/null -w "%{http_code}" "$BACKEND_URL/health" | grep -q "^200$"; then
+ echo "Backend is healthy."
+ break
+ fi
+
+ i=$((i+1))
+ if [ "$i" -ge "$MAX_RETRIES" ]; then
+ echo "Backend failed health check after $MAX_RETRIES retries. Exiting."
+ kill $BACKEND_PID
+ wait $BACKEND_PID
+ exit 1
+ fi
+
+ sleep "$RETRY_DELAY"
+done
+
# Run frontend as appuser in background
cd /app/frontend
su-exec appuser npm run start &