healthcheck.sh 878 B

1234567891011121314151617181920
  1. #!/bin/bash
  2. # Log check schedule
  3. LOGSCHEDULE=${LOGSCHEDULE:-1800}
  4. # Log difference in seconds
  5. _LOGDIFF=600
  6. # Log path
  7. _LOGDIR="/opt/analis/log"
  8. # Discover latest modified file
  9. _LOGFILE=${_LOGDIR}/AnalisatorService_$(date +%d-%m-%Y).txt
  10. #Check is it time to run _LOGFILE check
  11. if [[ $[ $(date +%s) - $(stat -c %Y "/opt/analis/checkfile.status") ] -gt ${LOGSCHEDULE} ]]; then
  12. touch /opt/analis/checkfile.status
  13. #Check difference between system time and latest modified file in logdir - if it's greater then $_LOGDIFF, then container is not healty
  14. if [[ $[ $(date +%s) - $(stat -c %Y "${_LOGFILE}") ] -gt ${_LOGDIFF} ]]; then
  15. echo -e $(date)" The difference between system time and latest modified file in logdir is "$[ $(date +%s) - $(stat -c %Y ${_LOGFILE}) ]" The service seems to be unhealty.\n\r" >> ${_LOGDIR}/healthcheck.log
  16. exit 1
  17. fi
  18. fi