healthcheck.sh 610 B

1234567891011121314
  1. #!/bin/bash
  2. # Log difference in seconds
  3. _LOGDIFF=600
  4. # Log path
  5. _LOGDIR="/opt/analis/log"
  6. # Discover latest modified file
  7. _LOGFILE=$( ls -t -d -1 ${_LOGDIR}/Analis* | head -1 )
  8. #Check difference between system time and latest modified file in logdir - if it's greater then $_LOGDIFF, then container is not healty
  9. if [[ $[ $(date +%s) - $(stat -c %Y "${_LOGFILE}"") ] -gt ${_LOGDIFF} ]]; then
  10. echo $(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." >> ${_LOGDIR}/healthcheck.log
  11. exit 1
  12. fi