Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- ### PURPOSE ###
- # This script is intended to be used with docker-compose.
- # With docker-compose, containers are not automatically restarted if they reach "unhealthy" status.
- # This script gets a list of unhealthy containers and attempts to restart them.
- ### USAGE ###
- # Define 'healthcheck' parameters for your services in your docker-compose.yml file.
- # Set up a cron task to run this periodically.
- ### KNOWN ISSUE ###
- # This does not work if you define service names with underscores ("_") in your docker-compose.yml file.
- # To work around this, just use dashes instead of underscores when defining your service names.
- # Set PATH here to prevent 'command not found' issues with running from cron.
- # If you still get 'command not found' in your syslog, run `which docker-compose` to find the directory that contains your docker-compose binary, then put it into this PATH.
- PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
- SCRIPTFILE=$(readlink -f "$0")
- SCRIPTPATH=$(dirname "$SCRIPTFILE")
- cd $SCRIPTPATH
- container_names=$(docker-compose ps | grep unhealthy | grep -oEi "^.+_(.+)_[0-9]+[[:space:]]" | cut -d _ -f 2)
- for container in $container_names
- do
- docker-compose restart $container
- done
Add Comment
Please, Sign In to add comment