mirror of
https://github.com/chatmail/relay.git
synced 2026-05-20 12:58:04 +00:00
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:
@@ -14,29 +14,38 @@ if [ -z "$MAIL_DOMAIN" ]; then
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
calculate_hash() {
|
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}'
|
find "$PATH_TO_SSL" -type f -exec sha1sum {} \; | sort | sha1sum | awk '{print $1}'
|
||||||
}
|
}
|
||||||
|
|
||||||
monitor_certificates() {
|
monitor_certificates() {
|
||||||
if [ "$ENABLE_CERTS_MONITORING" != "true" ]; then
|
if [ "$ENABLE_CERTS_MONITORING" != "true" ]; then
|
||||||
echo "Certs monitoring disabled."
|
echo "Certs monitoring disabled."
|
||||||
exit 0
|
return 0
|
||||||
fi
|
fi
|
||||||
|
|
||||||
current_hash=$(calculate_hash)
|
# Wait for certificate directory to exist before monitoring
|
||||||
previous_hash=$current_hash
|
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
|
while true; do
|
||||||
|
sleep "$CERTS_MONITORING_TIMEOUT"
|
||||||
current_hash=$(calculate_hash)
|
current_hash=$(calculate_hash)
|
||||||
if [[ "$current_hash" != "$previous_hash" ]]; then
|
if [ -n "$current_hash" ] && [ "$current_hash" != "$previous_hash" ]; then
|
||||||
# TODO: add an option to restart at a specific time interval
|
|
||||||
echo "[INFO] Certificate's folder hash was changed, reloading nginx, dovecot and postfix services."
|
echo "[INFO] Certificate's folder hash was changed, reloading nginx, dovecot and postfix services."
|
||||||
systemctl reload nginx.service
|
systemctl reload nginx.service
|
||||||
systemctl reload dovecot.service
|
systemctl reload dovecot.service
|
||||||
systemctl reload postfix.service
|
systemctl reload postfix.service
|
||||||
previous_hash=$current_hash
|
previous_hash=$current_hash
|
||||||
fi
|
fi
|
||||||
sleep $CERTS_MONITORING_TIMEOUT
|
|
||||||
done
|
done
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user