Skip to content

Commit b2957f0

Browse files
edomora97nickygerritsen
authored andcommitted
Add HEALTHCHECK to domserver Docker container
When running the Docker container for domserver, it is possible that one of nginx or php-fpm crashes/stops working. When this happens from outside the container the effects can be quite mysterious. Adding an health check allows the user to diagnose more quickly what happened. Running `docker ps`, in the column `STATUS` it is shown: `Up X minutes (healthy)` or `Up X minutes (unhealthy)` depending on the exit code of the health check script. To further diagnose the problem one can run `docker inspect domserver` (optionally piped to `jq '.[0].State.Health'`) and this will report diagnostic information like: ```json { "Status": "healthy", "FailingStreak": 0, "Log": [ { "Start": "2021-12-19T19:22:53.555071655+01:00", "End": "2021-12-19T19:22:54.012109556+01:00", "ExitCode": 0, "Output": "nginx ok | php ok | http ok" }, ... ] } ``` This health check probes supervisord for the status of the two services (nginx and php-fpm), as well as tries to reach the API with an HTTP request. This commit also fixes the deprecated `MAINTAINER` labels in the various Dockerfiles.
1 parent addcaaa commit b2957f0

File tree

4 files changed

+30
-4
lines changed

4 files changed

+30
-4
lines changed

docker/domserver/Dockerfile

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
FROM debian:stable-slim AS domserver-build
2-
MAINTAINER DOMjudge team <[email protected]>
2+
LABEL org.opencontainers.image.authors="DOMjudge team <[email protected]>"
33

44
ENV DEBIAN_FRONTEND=noninteractive
55

@@ -39,7 +39,7 @@ RUN /domjudge-src/build.sh
3939

4040
# Now create an image with the actual build in it
4141
FROM debian:stable-slim
42-
MAINTAINER DOMjudge team <[email protected]>
42+
LABEL org.opencontainers.image.authors="DOMjudge team <[email protected]>"
4343

4444
ENV DEBIAN_FRONTEND=noninteractive \
4545
CONTAINER_TIMEZONE=Europe/Amsterdam \
@@ -85,4 +85,7 @@ RUN chmod 700 /configure.sh && /configure.sh && rm -f /configure.sh
8585
# Expose HTTP port
8686
EXPOSE 80
8787

88+
# Healthchecking script
89+
HEALTHCHECK --interval=10s --timeout=10s --start-period=30s --retries=3 CMD [ "/scripts/bin/healthcheck" ]
90+
8891
CMD ["/scripts/start.sh"]
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#!/bin/bash
2+
3+
SERVICES=(nginx php)
4+
5+
ret=0
6+
for service in "${SERVICES[@]}"; do
7+
status=$(supervisorctl status "$service" | awk '{print $2}')
8+
if [ "$status" = "RUNNING" ]; then
9+
printf "%s ok | " "$service"
10+
else
11+
printf "%s %s | " "$service" "$status"
12+
ret=1
13+
fi
14+
done
15+
16+
if php -r 'exit(@file_get_contents("http://localhost/api/") === false ? 1 : 0);'; then
17+
printf "http ok"
18+
else
19+
printf "http error"
20+
ret=1
21+
fi
22+
23+
exit $ret

docker/judgehost/Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
FROM debian:stable
2-
MAINTAINER DOMjudge team <[email protected]>
2+
LABEL org.opencontainers.image.authors="DOMjudge team <[email protected]>"
33

44
ENV DEBIAN_FRONTEND=noninteractive \
55
CONTAINER_TIMEZONE=Europe/Amsterdam \

docker/judgehost/Dockerfile.build

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
FROM debian:stable-slim
2-
MAINTAINER DOMjudge team <[email protected]>
2+
LABEL org.opencontainers.image.authors="DOMjudge team <[email protected]>"
33

44
ENV DEBIAN_FRONTEND=noninteractive
55

0 commit comments

Comments
 (0)