Created
February 1, 2016 18:03
-
-
Save nickadam/4bfef53ffd6b7afc1cdf to your computer and use it in GitHub Desktop.
Docker Restart Failover Container
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
# Usage | |
if [ -z "$2" ] || [ "$1" == "--help" ] | |
then | |
echo "Please specify a container and pipework IP string" | |
echo " docker-restart-failover-container server-b-fo 10.0.0.11/16@10.0.0.1" | |
exit | |
fi | |
name="$1" | |
ip="$2" | |
interface="ovsbr0" | |
# Restart the container, wait a bit | |
if ! /usr/bin/docker restart "$name" | |
then | |
echo "Failed to start container $name" | |
exit 1 | |
fi | |
sleep 5 | |
# Setup interface, wait a bit | |
if ! /usr/local/sbin/pipework $interface "$name" "$ip" | |
then | |
echo "Failed to setup network $ip for $name" | |
exit 1 | |
fi | |
sleep 5 | |
# bridge the container’s eth1 to a new ovsbr0 | |
if ! /usr/bin/docker exec "$name" sh -c /usr/local/sbin/ovsbridge | |
then | |
echo "Failed to setup $name's openvswitch bridge" | |
exit 1 | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment