repl_health.sh 970 B

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