docker-keepalived/image/service/keepalived/container-start.sh

68 lines
2.4 KiB
Bash
Raw Normal View History

2015-06-16 09:13:22 +00:00
#!/bin/bash -e
2015-06-09 18:41:43 +00:00
FIRST_START_DONE="/etc/docker-keepalived-first-start-done"
# container first start
if [ ! -e "$FIRST_START_DONE" ]; then
# config folder is empty use bootstrap config if available
if [ ! -e /etc/keepalived/keepalived.conf ]; then
echo "No keepalived.conf provided using image default one"
2015-07-16 19:43:36 +00:00
if [ ! -e /osixia/service/keepalived/assets/keepalived.conf ]; then
echo "Error: No default keepalived.conf found in /osixia/service/keepalived/assets/keepalived.conf"
2015-06-09 18:41:43 +00:00
exit 1
else
2015-06-16 09:13:22 +00:00
2015-07-16 19:43:36 +00:00
ln -s /osixia/service/keepalived/assets/keepalived.conf /etc/keepalived/keepalived.conf
2015-06-15 14:04:40 +00:00
#
# bootstrap config
#
sed -i "s|{{ keepalived_interface }}|$KEEPALIVED_INTERFACE|g" /etc/keepalived/keepalived.conf
sed -i "s|{{ keepalived_priority }}|$KEEPALIVED_PRIORITY|g" /etc/keepalived/keepalived.conf
sed -i "s|{{ keepalived_password }}|$KEEPALIVED_PASSWORD|g" /etc/keepalived/keepalived.conf
2015-06-16 11:07:17 +00:00
if [ -n "$KEEPALIVED_NOTIFY" ]; then
2015-06-16 12:06:49 +00:00
sed -i "s|{{ keepalived_notify }}|notify \"$KEEPALIVED_NOTIFY\"|g" /etc/keepalived/keepalived.conf
2015-06-16 11:07:17 +00:00
else
sed -i "/{{ keepalived_notify }}/d" /etc/keepalived/keepalived.conf
fi
2015-06-15 14:04:40 +00:00
# unicast peers
KEEPALIVED_UNICAST_PEERS=($KEEPALIVED_UNICAST_PEERS)
for peer in "${KEEPALIVED_UNICAST_PEERS[@]}"
do
# it's just a peer
# stored in a variable
if [ -n "${!peer}" ]; then
2015-06-15 19:33:06 +00:00
sed -i "s|{{ keepalived_unicast_peers }}|${!peer}\n {{ keepalived_unicast_peers }}|g" /etc/keepalived/keepalived.conf
2015-06-15 14:04:40 +00:00
# directly
else
2015-06-15 19:33:06 +00:00
sed -i "s|{{ keepalived_unicast_peers }}|${peer}\n {{ keepalived_unicast_peers }}|g" /etc/keepalived/keepalived.conf
2015-06-15 14:04:40 +00:00
fi
done
2015-06-15 19:33:06 +00:00
sed -i "/{{ keepalived_unicast_peers }}/d" /etc/keepalived/keepalived.conf
2015-06-15 14:04:40 +00:00
# virtual ips
KEEPALIVED_VIRTUAL_IPS=($KEEPALIVED_VIRTUAL_IPS)
for vip in "${KEEPALIVED_VIRTUAL_IPS[@]}"
do
# it's just a peer
# stored in a variable
if [ -n "${!vip}" ]; then
2015-06-15 19:33:06 +00:00
sed -i "s|{{ keepalived_virtual_ips }}|${!vip}\n {{ keepalived_virtual_ips }}|g" /etc/keepalived/keepalived.conf
2015-06-15 14:04:40 +00:00
# directly
else
2015-06-15 19:33:06 +00:00
sed -i "s|{{ keepalived_virtual_ips }}|${vip}\n {{ keepalived_virtual_ips }}|g" /etc/keepalived/keepalived.conf
2015-06-15 14:04:40 +00:00
fi
done
2015-06-15 19:33:06 +00:00
sed -i "/{{ keepalived_virtual_ips }}/d" /etc/keepalived/keepalived.conf
2015-06-09 18:41:43 +00:00
fi
2015-06-16 09:13:22 +00:00
2015-06-09 18:41:43 +00:00
fi
touch $FIRST_START_DONE
fi
exit 0