2015-06-16 09:13:22 +00:00
|
|
|
#!/bin/bash -e
|
2015-06-09 18:41:43 +00:00
|
|
|
|
2016-01-17 11:12:04 +00:00
|
|
|
# set -x (bash debug) if log level is trace
|
|
|
|
# https://github.com/osixia/docker-light-baseimage/blob/stable/image/tool/log-helper
|
|
|
|
log-helper level eq trace && set -x
|
|
|
|
|
|
|
|
FIRST_START_DONE="${CONTAINER_STATE_DIR}/docker-keepalived-first-start-done"
|
2015-06-09 18:41:43 +00:00
|
|
|
# container first start
|
|
|
|
if [ ! -e "$FIRST_START_DONE" ]; then
|
|
|
|
|
2015-08-21 09:21:46 +00:00
|
|
|
#
|
|
|
|
# bootstrap config
|
|
|
|
#
|
2017-04-02 12:25:09 +00:00
|
|
|
sed -i "s|{{ KEEPALIVED_INTERFACE }}|$KEEPALIVED_INTERFACE|g" ${CONTAINER_SERVICE_DIR}/keepalived/assets/keepalived.conf
|
|
|
|
sed -i "s|{{ KEEPALIVED_PRIORITY }}|$KEEPALIVED_PRIORITY|g" ${CONTAINER_SERVICE_DIR}/keepalived/assets/keepalived.conf
|
|
|
|
sed -i "s|{{ KEEPALIVED_PASSWORD }}|$KEEPALIVED_PASSWORD|g" ${CONTAINER_SERVICE_DIR}/keepalived/assets/keepalived.conf
|
2015-08-21 09:21:46 +00:00
|
|
|
|
|
|
|
if [ -n "$KEEPALIVED_NOTIFY" ]; then
|
2017-04-02 12:25:09 +00:00
|
|
|
sed -i "s|{{ KEEPALIVED_NOTIFY }}|notify \"$KEEPALIVED_NOTIFY\"|g" ${CONTAINER_SERVICE_DIR}/keepalived/assets/keepalived.conf
|
|
|
|
chown keepalived_script:keepalived_script $KEEPALIVED_NOTIFY
|
2015-12-21 09:20:18 +00:00
|
|
|
chmod +x $KEEPALIVED_NOTIFY
|
2015-08-21 09:21:46 +00:00
|
|
|
else
|
2017-04-02 12:25:09 +00:00
|
|
|
sed -i "/{{ KEEPALIVED_NOTIFY }}/d" ${CONTAINER_SERVICE_DIR}/keepalived/assets/keepalived.conf
|
2015-08-21 09:21:46 +00:00
|
|
|
fi
|
2015-06-15 14:04:40 +00:00
|
|
|
|
2015-08-21 09:21:46 +00:00
|
|
|
# unicast peers
|
2016-01-19 19:59:40 +00:00
|
|
|
for peer in $(complex-bash-env iterate KEEPALIVED_UNICAST_PEERS)
|
2015-08-21 09:21:46 +00:00
|
|
|
do
|
2017-04-02 12:25:09 +00:00
|
|
|
sed -i "s|{{ KEEPALIVED_UNICAST_PEERS }}|${!peer}\n {{ KEEPALIVED_UNICAST_PEERS }}|g" ${CONTAINER_SERVICE_DIR}/keepalived/assets/keepalived.conf
|
2015-08-21 09:21:46 +00:00
|
|
|
done
|
2017-04-02 12:25:09 +00:00
|
|
|
sed -i "/{{ KEEPALIVED_UNICAST_PEERS }}/d" ${CONTAINER_SERVICE_DIR}/keepalived/assets/keepalived.conf
|
2015-08-21 09:21:46 +00:00
|
|
|
|
|
|
|
# virtual ips
|
2016-01-19 19:59:40 +00:00
|
|
|
for vip in $(complex-bash-env iterate KEEPALIVED_VIRTUAL_IPS)
|
2015-08-21 09:21:46 +00:00
|
|
|
do
|
2017-04-02 12:25:09 +00:00
|
|
|
sed -i "s|{{ KEEPALIVED_VIRTUAL_IPS }}|${!vip}\n {{ KEEPALIVED_VIRTUAL_IPS }}|g" ${CONTAINER_SERVICE_DIR}/keepalived/assets/keepalived.conf
|
2015-08-21 09:21:46 +00:00
|
|
|
done
|
2017-04-02 12:25:09 +00:00
|
|
|
sed -i "/{{ KEEPALIVED_VIRTUAL_IPS }}/d" ${CONTAINER_SERVICE_DIR}/keepalived/assets/keepalived.conf
|
2015-06-09 18:41:43 +00:00
|
|
|
|
|
|
|
touch $FIRST_START_DONE
|
|
|
|
fi
|
|
|
|
|
2016-08-27 08:37:00 +00:00
|
|
|
# try to delete virtual ips from interface
|
|
|
|
for vip in $(complex-bash-env iterate KEEPALIVED_VIRTUAL_IPS)
|
|
|
|
do
|
2017-04-02 12:25:09 +00:00
|
|
|
IP_INFO=$(ip addr list | grep ${!vip}) || 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 :("
|
|
|
|
continue
|
|
|
|
fi
|
|
|
|
|
|
|
|
ip addr del ${IP_IP} dev ${IP_INTERFACE} || true
|
2016-08-27 08:37:00 +00:00
|
|
|
done
|
|
|
|
|
2017-04-02 12:25:09 +00:00
|
|
|
if [ ! -e "/usr/local/etc/keepalived/keepalived.conf" ]; then
|
|
|
|
ln -sf ${CONTAINER_SERVICE_DIR}/keepalived/assets/keepalived.conf /usr/local/etc/keepalived/keepalived.conf
|
2016-01-18 20:38:30 +00:00
|
|
|
fi
|
|
|
|
|
2015-06-09 18:41:43 +00:00
|
|
|
exit 0
|