Guest User

Untitled

a guest
Jun 19th, 2018
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.21 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. ### PURPOSE ###
  4. # This script is intended to be used with docker-compose.
  5. # With docker-compose, containers are not automatically restarted if they reach "unhealthy" status.
  6. # This script gets a list of unhealthy containers and attempts to restart them.
  7.  
  8. ### USAGE ###
  9. # Define 'healthcheck' parameters for your services in your docker-compose.yml file.
  10. # Set up a cron task to run this periodically.
  11.  
  12. ### KNOWN ISSUE ###
  13. # This does not work if you define service names with underscores ("_") in your docker-compose.yml file.
  14. # To work around this, just use dashes instead of underscores when defining your service names.
  15.  
  16.  
  17. # Set PATH here to prevent 'command not found' issues with running from cron.
  18. # 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.
  19. PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
  20.  
  21. SCRIPTFILE=$(readlink -f "$0")
  22. SCRIPTPATH=$(dirname "$SCRIPTFILE")
  23.  
  24. cd $SCRIPTPATH
  25.  
  26. container_names=$(docker-compose ps | grep unhealthy | grep -oEi "^.+_(.+)_[0-9]+[[:space:]]" | cut -d _ -f 2)
  27.  
  28. for container in $container_names
  29. do
  30. docker-compose restart $container
  31. done
Add Comment
Please, Sign In to add comment