Docker Community Forums

Share and learn in the Docker community.

Exit 1 if log file is not updated in last 5 mins

I am trying to add a health check in docker-compose if log file is not updated in last 5 mins then exit.

Tried solution

find /path/to/log/log* -mmin +15 -mmin -30 | xargs -L1 exit1 
time=`ls -l /usr/home/log/test.log|awk '{ print $8 }'`

sleep 300

time1=`ls -l /usr/home/log/test.log|awk '{ print $8 }'`
 
if [ $time -eq $time1 ]; then
        exit1
fi

Above function might work but how I make it work with docker-compose health check. Is there any better option available?

  test:
    image: alpine
    container_name: alpine
    ports:
      - 8093:8080
    healthcheck:
      test: <some function to check logs file is updating> || exit 1
      interval: 60s
      timeout: 10s
      retries: 3