repl_health.sh 868 B

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