Skip to content

Instantly share code, notes, and snippets.

@jmbarbier
Last active January 18, 2016 01:26
Show Gist options
  • Save jmbarbier/92b15f2528fd8992299b to your computer and use it in GitHub Desktop.
Save jmbarbier/92b15f2528fd8992299b to your computer and use it in GitHub Desktop.
Gandi systemd / docker failure at reboot testcase.
#!/bin/bash
# Test restart d'une VM sur instance de base Gandi Debian 8 + install par défaut de docker
VM=dockersystemd
gandi vm create --datacenter LU --memory 1024 --cores 2 --ip-version 4 --hostname $VM --image "Debian 8 64 bits (HVM)" --size 10G
echo "Installing docker"
gandi vm ssh $VM 'apt-get update && apt-get install -y curl'
gandi vm ssh $VM 'curl -sSL https://get.docker.com/ | sh'
echo "Launching a nginx container, bind to 0.0.0.0:80 and with restart=always"
gandi vm ssh $VM 'docker run -d --name nginx --restart=always -p 0.0.0.0:80:80 nginx'
echo "Testing container"
IP=`gandi vm info $VM | grep ip4 | sed 's/ip4 *: //g'`
curl http://$IP | grep html
echo "Let's restart the vm"
gandi vm stop $VM
gandi vm start $VM
sleep 20
echo "Nginx should be alive now, but it's not (timeout)"
curl http://$IP
echo "Checking if nginx container is running"
gandi vm ssh $VM "docker ps | grep nginx"
echo "Restarting container"
gandi vm ssh $VM "docker restart nginx"
echo "Nginx still not alive"
curl http://$IP
echo "It's because eth0 is not ready when docker starts"
echo "Restarting docker after network is ready does the trick"
gandi vm ssh $VM "service docker restart"
sleep 10
curl http://$IP | grep html
echo "Checking with CONFIG_NETWORK=0"
gandi vm ssh $VM "sed -i 's/CONFIG_NETWORK=1/CONFIG_NETWORK=0/g' /etc/default/gandi"
gandi vm stop $VM
gandi vm start $VM
sleep 20
echo "It still fails"
curl http://$IP | grep html
echo "My ugly hack for now : sleep 20 on ExecStartPre in docker.service"
gandi vm ssh $VM "cp /lib/systemd/system/docker.service /etc/systemd/system/"
gandi vm ssh $VM "sed -i 's/ExecStart=/ExecStartPre=\/bin\/sleep 20\nExecStart=/g' /etc/systemd/system/docker.service"
gandi vm ssh $VM "systemctl daemon-reload"
gandi vm stop $VM
gandi vm start $VM
sleep 20
echo "It works !! but if network config takes more than 20secs, it fails..."
curl http://$IP | grep html
gandi vm stop $VM
gandi vm delete $VM
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment