From 57f9327d4d83d3dbaad8273011bc1aaa6d4173ac Mon Sep 17 00:00:00 2001 From: j4n Date: Mon, 16 Feb 2026 19:53:56 +0100 Subject: [PATCH] =?UTF-8?q?docker:=20fix=20cert=20monitoring=20=E2=80=94?= =?UTF-8?q?=20wait=20for=20certs=20dir,=20use=20return=20not=20exit?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fix bugs in certificate monitoring function: - `exit 0` inside monitor_certificates() would kill the background process - calculate_hash() now checks dir existence instead of silenty dying - Added wait loop until $PATH_TO_SSL exists before monitoring Files: docker/files/setup_chatmail_docker.sh:16-41 --- docker/files/setup_chatmail_docker.sh | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/docker/files/setup_chatmail_docker.sh b/docker/files/setup_chatmail_docker.sh index 74ab0aed..285cfef5 100755 --- a/docker/files/setup_chatmail_docker.sh +++ b/docker/files/setup_chatmail_docker.sh @@ -14,29 +14,38 @@ if [ -z "$MAIL_DOMAIN" ]; then fi calculate_hash() { + if [ ! -d "$PATH_TO_SSL" ]; then + echo "" + return 0 + fi find "$PATH_TO_SSL" -type f -exec sha1sum {} \; | sort | sha1sum | awk '{print $1}' } monitor_certificates() { if [ "$ENABLE_CERTS_MONITORING" != "true" ]; then echo "Certs monitoring disabled." - exit 0 + return 0 fi - current_hash=$(calculate_hash) - previous_hash=$current_hash + # Wait for certificate directory to exist before monitoring + echo "[INFO] Waiting for certificate directory: $PATH_TO_SSL" + while [ ! -d "$PATH_TO_SSL" ]; do + sleep "$CERTS_MONITORING_TIMEOUT" + done + echo "[INFO] Certificate directory found, starting monitoring." + + previous_hash=$(calculate_hash) while true; do + sleep "$CERTS_MONITORING_TIMEOUT" current_hash=$(calculate_hash) - if [[ "$current_hash" != "$previous_hash" ]]; then - # TODO: add an option to restart at a specific time interval + if [ -n "$current_hash" ] && [ "$current_hash" != "$previous_hash" ]; then echo "[INFO] Certificate's folder hash was changed, reloading nginx, dovecot and postfix services." systemctl reload nginx.service systemctl reload dovecot.service systemctl reload postfix.service previous_hash=$current_hash fi - sleep $CERTS_MONITORING_TIMEOUT done }