trim_logs.sh 1.0 KB

123456789101112131415161718192021222324252627
  1. #!/bin/bash
  2. catch_non_zero() {
  3. CMD=${1}
  4. ${CMD} > /dev/null
  5. EC=$?
  6. if [ ${EC} -ne 0 ]; then
  7. echo "Command ${CMD} failed to execute, exit code was ${EC}"
  8. fi
  9. }
  10. source /source_env.sh
  11. # Do not attempt to write to slave
  12. if [[ ! -z ${REDIS_SLAVEOF_IP} ]]; then
  13. REDIS_CMDLINE="redis-cli -h ${REDIS_SLAVEOF_IP} -p ${REDIS_SLAVEOF_PORT}"
  14. else
  15. REDIS_CMDLINE="redis-cli -h redis -p 6379"
  16. fi
  17. catch_non_zero "${REDIS_CMDLINE} LTRIM ACME_LOG 0 ${LOG_LINES}"
  18. catch_non_zero "${REDIS_CMDLINE} LTRIM POSTFIX_MAILLOG 0 ${LOG_LINES}"
  19. catch_non_zero "${REDIS_CMDLINE} LTRIM DOVECOT_MAILLOG 0 ${LOG_LINES}"
  20. catch_non_zero "${REDIS_CMDLINE} LTRIM SOGO_LOG 0 ${LOG_LINES}"
  21. catch_non_zero "${REDIS_CMDLINE} LTRIM NETFILTER_LOG 0 ${LOG_LINES}"
  22. catch_non_zero "${REDIS_CMDLINE} LTRIM AUTODISCOVER_LOG 0 ${LOG_LINES}"
  23. catch_non_zero "${REDIS_CMDLINE} LTRIM API_LOG 0 ${LOG_LINES}"
  24. catch_non_zero "${REDIS_CMDLINE} LTRIM RL_LOG 0 ${LOG_LINES}"
  25. catch_non_zero "${REDIS_CMDLINE} LTRIM WATCHDOG_LOG 0 ${LOG_LINES}"
  26. catch_non_zero "${REDIS_CMDLINE} LTRIM CRON_LOG 0 ${LOG_LINES}"