Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- # Usage: test_docker.sh <port> <sleepfor>
- # Get parameters from the arguments passed
- port=$1
- sleepfor=$2
- # Check if no argments has been passed to script
- if [ "$#" -le "0" ]; then
- echo Not enough parameters passed.
- echo
- echo Usage:
- echo "test_docker.sh <port> <sleepfor>"
- exit
- fi
- # If the second argument hasn't been passed - set the sleep value to a default value
- if [ "$sleepfor" = "" ]; then
- echo "Setting the default value for sleepfor to 1 second"
- sleepfor=1
- fi
- # CentOS/RedHat: yum install nc
- # Fedora 22+: dmf install nc
- # Ubuntu: sudo apt-get install netcat
- # nc -zv localhost $port
- # Begin the loop
- while [ true ]
- do
- # Running the port test command
- nc -zv localhost $port &> /dev/null
- # Check for errorlevel. 0 - command returned good value, >0 - not good (probably Docker is not present on this port)
- if [ "$?" -eq "1" ]; then
- echo Docker is not running on this port. Retrying...
- sleep $sleepfor
- # Do another loop, do not proceed to a restart containers routine
- continue
- fi
- echo Something is running on this port.
- sleep $sleepfor
- # TODO: Restart containers here:
- #docker restart ...
- # Get out of the loop
- break
- done
- echo Docker containers has been restarted
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement