Skip to content

Commit 10ab3cc

Browse files
committed
Autodetect the default network interface
Closes #13
1 parent 9dd4ca4 commit 10ab3cc

File tree

3 files changed

+15
-2
lines changed

3 files changed

+15
-2
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ Environment variables defaults are set in **image/environment/default.yaml**
7777
See how to [set your own environment variables](#set-your-own-environment-variables)
7878

7979

80-
- **KEEPALIVED_INTERFACE**: Keepalived network interface. Defaults to `eth0`
80+
- **KEEPALIVED_INTERFACE**: Keepalived network interface. Autodetected to interface with default route (see `ip route`)
8181
- **KEEPALIVED_PASSWORD**: Keepalived password. Defaults to `d0cker`
8282
- **KEEPALIVED_PRIORITY** Keepalived node priority. Defaults to `150`
8383
- **KEEPALIVED_ROUTER_ID** Keepalived virtual router ID. Defaults to `51`

image/environment/default.yaml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
KEEPALIVED_COMMAND_LINE_ARGUMENTS: --log-detail --dump-conf
22

3-
KEEPALIVED_INTERFACE: eth0
3+
# set the interface here to disable the default interface auto detection
4+
# KEEPALIVED_INTERFACE: eth0
5+
46
KEEPALIVED_PASSWORD: d0cker
57

68
# For electing MASTER, highest priority wins.

image/service/keepalived/startup.sh

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,17 @@ FIRST_START_DONE="${CONTAINER_STATE_DIR}/docker-keepalived-first-start-done"
88
# container first start
99
if [ ! -e "$FIRST_START_DONE" ]; then
1010

11+
# autodetect the default network interface
12+
if [ -z "$KEEPALIVED_INTERFACE" ]; then
13+
KEEPALIVED_INTERFACE=$(ip route | awk '/default/ { print $5 }')
14+
if [ -z "$KEEPALIVED_INTERFACE" ]; then
15+
echo "ERROR: Couldn't autodetect the default network interface, specify it manually."
16+
exit 1
17+
else
18+
echo "Autodetected default network interface: $KEEPALIVED_INTERFACE"
19+
fi
20+
fi
21+
1122
#
1223
# bootstrap config
1324
#

0 commit comments

Comments
 (0)