Skip to content

Commit

Permalink
Make sure db container waits for etcd to be ready before trying to re…
Browse files Browse the repository at this point in the history
…gister IP
  • Loading branch information
vidarl committed Oct 28, 2014
1 parent f672d28 commit c666194
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
2 changes: 1 addition & 1 deletion dockerfiles/mysql/register_ip_and_run.sh
Expand Up @@ -5,7 +5,7 @@ set -e
source ./etcd_functions

if [ aa$ETCD_ENABLED == "aayes" ]; then
wait_for_etcd_to_get_online
set_etcd_value "/ezpublish/db_ip" `get_container_ip`
fi

/run.sh
21 changes: 21 additions & 0 deletions files/etcd_functions
@@ -1,5 +1,7 @@
#!/bin/bash

MAXTRY=10

function get_bridge_ip
{
ip route| awk '/default/ { print $3 }'
Expand All @@ -11,6 +13,25 @@ function get_container_ip
hostname --all-ip-addresses
}

function wait_for_etcd_to_get_online
{
local ETCDUP
local TRY
ETCDUP=false
TRY=1
while [ $ETCDUP == "false" ]; do
echo Contacting etcd, attempt :$TRY
etcdctl --peers="http://172.17.42.1:4001" ls / && ETCDUP="true"
let TRY=$TRY+1
if [ $TRY -gt $MAXTRY ]; then
echo Max limit reached. Not able to connect to etcd
exit 1;
fi
sleep 2;
done

}

# $1 is key, for instance "/message"
function get_etcd_value
{
Expand Down

0 comments on commit c666194

Please sign in to comment.