Skip to content

Commit 5eb9988

Browse files
committed
Wait for backend to start before starting frontend.
1 parent 0cb4370 commit 5eb9988

File tree

4 files changed

+28
-2
lines changed

4 files changed

+28
-2
lines changed

Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ WORKDIR /app
2828

2929
# Prepare environment
3030
RUN mkdir /config \
31-
&& apk add --no-cache nodejs npm libc6-compat shadow su-exec bash
31+
&& apk add --no-cache nodejs npm libc6-compat shadow su-exec bash curl
3232

3333
# Copy frontend
3434
COPY --from=frontend-build /frontend/node_modules ./frontend/node_modules

backend/Extensions/NWebDavOptionsExtensions.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ public static class NWebDavOptionsExtensions
88
public static Func<HttpContext, bool> GetFilter(this NWebDavOptions options)
99
{
1010
return context => !context.Request.Path.StartsWithSegments("/api") &&
11-
!context.Request.Path.StartsWithSegments("/view");
11+
!context.Request.Path.StartsWithSegments("/view") &&
12+
!context.Request.Path.StartsWithSegments("/health");
1213
}
1314
}

backend/Program.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ static async Task Main(string[] args)
5151
var builder = WebApplication.CreateBuilder(args);
5252
builder.Host.UseSerilog();
5353
builder.Services.AddControllers();
54+
builder.Services.AddHealthChecks();
5455
builder.Services
5556
.AddSingleton(configManager)
5657
.AddSingleton<UsenetStreamingClient>()
@@ -85,6 +86,7 @@ static async Task Main(string[] args)
8586

8687
// run
8788
var app = builder.Build();
89+
app.MapHealthChecks("/health");
8890
app.UseSerilogRequestLogging();
8991
app.UseMiddleware<ExceptionMiddleware>();
9092
app.UseAuthentication();

entrypoint.sh

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,29 @@ cd /app/backend
5454
su-exec appuser ./NzbWebDAV &
5555
BACKEND_PID=$!
5656

57+
# Wait for backend health check
58+
echo "Waiting for backend to start."
59+
MAX_RETRIES=30
60+
RETRY_DELAY=1
61+
i=0
62+
while true; do
63+
echo "Checking backend health: $BACKEND_URL/health ..."
64+
if curl -s -o /dev/null -w "%{http_code}" "$BACKEND_URL/health" | grep -q "^200$"; then
65+
echo "Backend is healthy."
66+
break
67+
fi
68+
69+
i=$((i+1))
70+
if [ "$i" -ge "$MAX_RETRIES" ]; then
71+
echo "Backend failed health check after $MAX_RETRIES retries. Exiting."
72+
kill $BACKEND_PID
73+
wait $BACKEND_PID
74+
exit 1
75+
fi
76+
77+
sleep "$RETRY_DELAY"
78+
done
79+
5780
# Run frontend as appuser in background
5881
cd /app/frontend
5982
su-exec appuser npm run start &

0 commit comments

Comments
 (0)