docker: fix cert monitoring — wait for certs dir, use return not exit

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
This commit is contained in:
j4n
2026-02-16 19:53:56 +01:00
parent e99d979eb8
commit 57f9327d4d

View File

@@ -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
}