Skip to content

Commit 7a8526d

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

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

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)