Skip to content

Instantly share code, notes, and snippets.

@nickadam
Created February 1, 2016 18:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nickadam/4bfef53ffd6b7afc1cdf to your computer and use it in GitHub Desktop.
Save nickadam/4bfef53ffd6b7afc1cdf to your computer and use it in GitHub Desktop.
Docker Restart Failover Container
#!/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