Matthias Andreas Benkard | b382b10 | 2021-01-02 15:32:21 +0100 | [diff] [blame] | 1 | #!/bin/bash |
| 2 | |
| 3 | source /source_env.sh |
| 4 | |
| 5 | # Do not attempt to write to slave |
| 6 | if [[ ! -z ${REDIS_SLAVEOF_IP} ]]; then |
| 7 | REDIS_CMDLINE="redis-cli -h ${REDIS_SLAVEOF_IP} -p ${REDIS_SLAVEOF_PORT}" |
| 8 | else |
| 9 | REDIS_CMDLINE="redis-cli -h redis -p 6379" |
| 10 | fi |
| 11 | |
| 12 | # Is replication active? |
| 13 | # grep on file is less expensive than doveconf |
| 14 | if ! grep -qi mail_replica /etc/dovecot/dovecot.conf; then |
| 15 | ${REDIS_CMDLINE} SET DOVECOT_REPL_HEALTH 1 > /dev/null |
| 16 | exit |
| 17 | fi |
| 18 | |
| 19 | FAILED_SYNCS=$(doveadm replicator status | grep "Waiting 'failed' requests" | grep -oE '[0-9]+') |
| 20 | |
| 21 | # Set amount of failed jobs as DOVECOT_REPL_HEALTH |
| 22 | # 1 failed job for mailcow.local is expected and healthy |
| 23 | if [[ "${FAILED_SYNCS}" != 0 ]] && [[ "${FAILED_SYNCS}" != 1 ]]; then |
| 24 | printf "Dovecot replicator has %d failed jobs\n" "${FAILED_SYNCS}" |
| 25 | ${REDIS_CMDLINE} SET DOVECOT_REPL_HEALTH "${FAILED_SYNCS}" > /dev/null |
| 26 | else |
| 27 | ${REDIS_CMDLINE} SET DOVECOT_REPL_HEALTH 1 > /dev/null |
| 28 | fi |