mirror of
https://github.com/chatmail/relay.git
synced 2026-05-10 16:04:37 +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
|
||||
|
||||
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
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user