From 6910751d38034f5afdda39f8433067a55e7f33da Mon Sep 17 00:00:00 2001 From: Bertrand Gouny Date: Sun, 2 Apr 2017 16:03:27 +0200 Subject: [PATCH] wait config file + fix ip detection --- image/service/keepalived/finish.sh | 8 ++++---- image/service/keepalived/install.sh | 5 +++++ image/service/keepalived/process.sh | 8 ++++++++ image/service/keepalived/startup.sh | 8 ++++---- 4 files changed, 21 insertions(+), 8 deletions(-) create mode 100755 image/service/keepalived/install.sh diff --git a/image/service/keepalived/finish.sh b/image/service/keepalived/finish.sh index 6d873d3..3276d22 100755 --- a/image/service/keepalived/finish.sh +++ b/image/service/keepalived/finish.sh @@ -7,20 +7,20 @@ log-helper level eq trace && set -x # try to delete virtual ips from interface for vip in $(complex-bash-env iterate KEEPALIVED_VIRTUAL_IPS) do - IP_INFO=$(ip addr list | grep ${!vip}) || continue + IP=$(echo ${!vip} | awk '{print $1}'} + IP_INFO=$(ip addr list | grep ${IP}) || continue IP_V6=$(echo "${IP_INFO}" | grep "inet6") - IP_IP=$(echo "${IP_INFO}" | awk '{print $2}') # ipv4 if [ -z "${IP_V6}" ]; then IP_INTERFACE=$(echo "${IP_INFO}" | awk '{print $5}') # ipv6 else - echo "skipping address: ${IP_IP} - ipv6 not supported yet :(" + echo "skipping address: ${IP} - ipv6 not supported yet :(" continue fi - ip addr del ${IP_IP} dev ${IP_INTERFACE} || true + ip addr del ${IP} dev ${IP_INTERFACE} || true done exit 0 diff --git a/image/service/keepalived/install.sh b/image/service/keepalived/install.sh new file mode 100755 index 0000000..773d108 --- /dev/null +++ b/image/service/keepalived/install.sh @@ -0,0 +1,5 @@ +#!/bin/bash -e +# this script is run during the image build + +# delete keepalived default config file +rm /usr/local/etc/keepalived/keepalived.conf diff --git a/image/service/keepalived/process.sh b/image/service/keepalived/process.sh index a787f4b..7e634b7 100755 --- a/image/service/keepalived/process.sh +++ b/image/service/keepalived/process.sh @@ -4,4 +4,12 @@ # https://github.com/osixia/docker-light-baseimage/blob/stable/image/tool/log-helper log-helper level eq trace && set -x +echo -n "Waiting config file /usr/local/etc/keepalived/keepalived.conf" +while [ ! -e "/usr/local/etc/keepalived/keepalived.conf" ] +do + echo -n "." + sleep +done +echo "ok" + exec /usr/local/sbin/keepalived -f /usr/local/etc/keepalived/keepalived.conf --dont-fork --log-console ${KEEPALIVED_COMMAND_LINE_ARGUMENTS} diff --git a/image/service/keepalived/startup.sh b/image/service/keepalived/startup.sh index 36bdf34..8470897 100755 --- a/image/service/keepalived/startup.sh +++ b/image/service/keepalived/startup.sh @@ -43,20 +43,20 @@ fi # try to delete virtual ips from interface for vip in $(complex-bash-env iterate KEEPALIVED_VIRTUAL_IPS) do - IP_INFO=$(ip addr list | grep ${!vip}) || continue + IP=$(echo ${!vip} | awk '{print $1}'} + IP_INFO=$(ip addr list | grep ${IP}) || continue IP_V6=$(echo "${IP_INFO}" | grep "inet6") - IP_IP=$(echo "${IP_INFO}" | awk '{print $2}') # ipv4 if [ -z "${IP_V6}" ]; then IP_INTERFACE=$(echo "${IP_INFO}" | awk '{print $5}') # ipv6 else - echo "skipping address: ${IP_IP} - ipv6 not supported yet :(" + echo "skipping address: ${IP} - ipv6 not supported yet :(" continue fi - ip addr del ${IP_IP} dev ${IP_INTERFACE} || true + ip addr del ${IP} dev ${IP_INTERFACE} || true done if [ ! -e "/usr/local/etc/keepalived/keepalived.conf" ]; then