docker-keepalived/image/service/keepalived/startup.sh

46 lines
1.8 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
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
2016-01-17 11:12:04 +00:00
ln -sf ${CONTAINER_SERVICE_DIR}/keepalived/assets/keepalived.conf /etc/keepalived/keepalived.conf
2015-08-21 09:21:46 +00:00
#
# bootstrap config
#
2015-12-22 16:40:24 +00:00
sed -i --follow-symlinks "s|{{ keepalived_interface }}|$KEEPALIVED_INTERFACE|g" /etc/keepalived/keepalived.conf
sed -i --follow-symlinks "s|{{ keepalived_priority }}|$KEEPALIVED_PRIORITY|g" /etc/keepalived/keepalived.conf
sed -i --follow-symlinks "s|{{ keepalived_password }}|$KEEPALIVED_PASSWORD|g" /etc/keepalived/keepalived.conf
2015-08-21 09:21:46 +00:00
if [ -n "$KEEPALIVED_NOTIFY" ]; then
2015-12-22 16:40:24 +00:00
sed -i --follow-symlinks "s|{{ keepalived_notify }}|notify \"$KEEPALIVED_NOTIFY\"|g" /etc/keepalived/keepalived.conf
2015-12-21 09:20:18 +00:00
chmod +x $KEEPALIVED_NOTIFY
2015-08-21 09:21:46 +00:00
else
2015-12-22 16:40:24 +00:00
sed -i --follow-symlinks "/{{ keepalived_notify }}/d" /etc/keepalived/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-17 11:24:24 +00:00
for peer in $(complex-bash-env iterate "${KEEPALIVED_UNICAST_PEERS}")
2015-08-21 09:21:46 +00:00
do
2016-01-17 11:24:24 +00:00
sed -i --follow-symlinks "s|{{ keepalived_unicast_peers }}|${peer}\n {{ keepalived_unicast_peers }}|g" /etc/keepalived/keepalived.conf
2015-08-21 09:21:46 +00:00
done
2015-12-22 16:40:24 +00:00
sed -i --follow-symlinks "/{{ keepalived_unicast_peers }}/d" /etc/keepalived/keepalived.conf
2015-08-21 09:21:46 +00:00
# virtual ips
2016-01-17 11:24:24 +00:00
for vip in $(complex-bash-env iterate "${KEEPALIVED_VIRTUAL_IPS}")
2015-08-21 09:21:46 +00:00
do
2016-01-17 11:24:24 +00:00
sed -i --follow-symlinks "s|{{ keepalived_virtual_ips }}|${vip}\n {{ keepalived_virtual_ips }}|g" /etc/keepalived/keepalived.conf
2015-08-21 09:21:46 +00:00
done
2015-12-22 16:40:24 +00:00
sed -i --follow-symlinks "/{{ keepalived_virtual_ips }}/d" /etc/keepalived/keepalived.conf
2015-06-09 18:41:43 +00:00
touch $FIRST_START_DONE
fi
exit 0