healthcheck: parallel bash probe for smtp/imap on all 4 ports

This commit is contained in:
c41ms0n 2026-04-23 00:53:32 +03:00
parent dad7066244
commit 036e49faf0
4 changed files with 84 additions and 16 deletions

View file

@ -111,7 +111,7 @@ EXPOSE 143/tcp
WORKDIR /protonmail
COPY gpgparams entrypoint.sh /protonmail/
COPY gpgparams entrypoint.sh healthcheck.sh /protonmail/
COPY --from=build /build/bridge /protonmail/
COPY --from=build /build/proton-bridge /protonmail/
@ -128,15 +128,11 @@ RUN --mount=type=cache,target=/var/cache/apt,sharing=locked \
reptyr) apt-get install -y --no-install-recommends reptyr ;; \
*) echo "Unsupported PTY_TOOL: ${PTY_TOOL}. Supported: dtach, abduco, reptyr." >&2 ; exit 1 ;; \
esac \
&& chmod +x /protonmail/entrypoint.sh \
&& chmod +x /protonmail/entrypoint.sh /protonmail/healthcheck.sh \
&& rm -rf /var/lib/apt/lists/*
HEALTHCHECK --interval=30s --timeout=5s --retries=3 --start-period=120s \
CMD /bin/bash -c \
"true < /dev/tcp/localhost/25 \
&& true < /dev/tcp/localhost/143 \
&& true < /dev/tcp/localhost/1025 \
&& true < /dev/tcp/localhost/1143"
HEALTHCHECK --interval=30s --timeout=10s --retries=3 --start-period=120s \
CMD /protonmail/healthcheck.sh
ENTRYPOINT ["/protonmail/entrypoint.sh"]
CMD ["run"]

38
build/healthcheck.sh Normal file
View file

@ -0,0 +1,38 @@
#!/bin/bash
set -euo pipefail
# Proton Bridge healthcheck — probes all 4 ports in parallel.
# Exit 0 = healthy, 1 = unhealthy (Docker HEALTHCHECK contract).
TIMEOUT=5 # seconds per probe
check_smtp() {
local port=$1
echo 'QUIT' | socat -T${TIMEOUT} - TCP4:localhost:${port} 2>/dev/null \
| grep -q '^220'
}
check_imap() {
local port=$1
printf 'A1 LOGOUT\r\n' | socat -T${TIMEOUT} - TCP4:localhost:${port} 2>/dev/null \
| grep -q '^\* OK'
}
# Fire all probes in parallel, capture PIDs
check_smtp 25 & PID_SMTP_25=$!
check_imap 143 & PID_IMAP_143=$!
check_smtp 1025 & PID_SMTP_1025=$!
check_imap 1143 & PID_IMAP_1143=$!
# Collect results — || prevents set -e from exiting early on probe failure
FAIL=0
wait $PID_SMTP_25 || { echo "FAIL smtp:25"; FAIL=1; }
wait $PID_IMAP_143 || { echo "FAIL imap:143"; FAIL=1; }
wait $PID_SMTP_1025 || { echo "FAIL smtp:1025"; FAIL=1; }
wait $PID_IMAP_1143 || { echo "FAIL imap:1143"; FAIL=1; }
if [[ $FAIL -eq 0 ]]; then
echo "OK smtp:25 imap:143 smtp:1025 imap:1143"
fi
exit $FAIL