Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Autodetect the default network interface #45

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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