Skip to content

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 10ab3cc
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 2 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ Environment variables defaults are set in **image/environment/default.yaml**
See how to [set your own environment variables](#set-your-own-environment-variables)


- **KEEPALIVED_INTERFACE**: Keepalived network interface. Defaults to `eth0`
- **KEEPALIVED_INTERFACE**: Keepalived network interface. Autodetected to interface with default route (see `ip route`)
- **KEEPALIVED_PASSWORD**: Keepalived password. Defaults to `d0cker`
- **KEEPALIVED_PRIORITY** Keepalived node priority. Defaults to `150`
- **KEEPALIVED_ROUTER_ID** Keepalived virtual router ID. Defaults to `51`
Expand Down
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 10ab3cc

Please sign in to comment.