Skip to content
This repository has been archived by the owner on Aug 18, 2022. It is now read-only.

Commit

Permalink
Autodetect the default network interface
Browse files Browse the repository at this point in the history
Closes #13
  • Loading branch information
linkvt committed Nov 22, 2020
1 parent 9dd4ca4 commit ebe58a1
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
4 changes: 3 additions & 1 deletion image/environment/default.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
KEEPALIVED_COMMAND_LINE_ARGUMENTS: --log-detail --dump-conf

KEEPALIVED_INTERFACE: eth0
# set the interface here to disable the default interface auto detection
# KEEPALIVED_INTERFACE: eth0

KEEPALIVED_PASSWORD: d0cker

# For electing MASTER, highest priority wins.
Expand Down
11 changes: 11 additions & 0 deletions image/service/keepalived/startup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,17 @@ FIRST_START_DONE="${CONTAINER_STATE_DIR}/docker-keepalived-first-start-done"
# container first start
if [ ! -e "$FIRST_START_DONE" ]; then

# autodetect the default network interface
if [ -z "$KEEPALIVED_INTERFACE" ]; then
KEEPALIVED_INTERFACE=$(ip route | awk '/default/ { print $5 }')
if [ -z "$KEEPALIVED_INTERFACE" ]; then
echo "Error: Couldn't autodetect the default network interface, specify it manually."
exit 1
else
echo "Autodetected default network interface: $KEEPALIVED_INTERFACE"
fi
fi

#
# bootstrap config
#
Expand Down

0 comments on commit ebe58a1

Please sign in to comment.