Skip to content

Swap from "hostname --ip-address" to "ip address" for IP address scraping (especially for Swarm Mode where we sometimes have an additional shared VIP) #146

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

Merged
merged 1 commit into from
Apr 25, 2018
Merged
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
16 changes: 14 additions & 2 deletions 2.1/docker-entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,30 @@ if [ "$1" = 'cassandra' -a "$(id -u)" = '0' ]; then
exec gosu cassandra "$BASH_SOURCE" "$@"
fi

_ip_address() {
# scrape the first non-localhost IP address of the container
# in Swarm Mode, we often get two IPs -- the container IP, and the (shared) VIP, and the container IP should always be first
ip address | awk '
$1 == "inet" && $2 !~ /^127[.]/ {
gsub(/\/.+$/, "", $2)
print $2
exit
}
'
}

if [ "$1" = 'cassandra' ]; then
: ${CASSANDRA_RPC_ADDRESS='0.0.0.0'}

: ${CASSANDRA_LISTEN_ADDRESS='auto'}
if [ "$CASSANDRA_LISTEN_ADDRESS" = 'auto' ]; then
CASSANDRA_LISTEN_ADDRESS="$(hostname --ip-address)"
CASSANDRA_LISTEN_ADDRESS="$(_ip_address)"
fi

: ${CASSANDRA_BROADCAST_ADDRESS="$CASSANDRA_LISTEN_ADDRESS"}

if [ "$CASSANDRA_BROADCAST_ADDRESS" = 'auto' ]; then
CASSANDRA_BROADCAST_ADDRESS="$(hostname --ip-address)"
CASSANDRA_BROADCAST_ADDRESS="$(_ip_address)"
fi
: ${CASSANDRA_BROADCAST_RPC_ADDRESS:=$CASSANDRA_BROADCAST_ADDRESS}

Expand Down
16 changes: 14 additions & 2 deletions 2.2/docker-entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,30 @@ if [ "$1" = 'cassandra' -a "$(id -u)" = '0' ]; then
exec gosu cassandra "$BASH_SOURCE" "$@"
fi

_ip_address() {
# scrape the first non-localhost IP address of the container
# in Swarm Mode, we often get two IPs -- the container IP, and the (shared) VIP, and the container IP should always be first
ip address | awk '
$1 == "inet" && $2 !~ /^127[.]/ {
gsub(/\/.+$/, "", $2)
print $2
exit
}
'
}

if [ "$1" = 'cassandra' ]; then
: ${CASSANDRA_RPC_ADDRESS='0.0.0.0'}

: ${CASSANDRA_LISTEN_ADDRESS='auto'}
if [ "$CASSANDRA_LISTEN_ADDRESS" = 'auto' ]; then
CASSANDRA_LISTEN_ADDRESS="$(hostname --ip-address)"
CASSANDRA_LISTEN_ADDRESS="$(_ip_address)"
fi

: ${CASSANDRA_BROADCAST_ADDRESS="$CASSANDRA_LISTEN_ADDRESS"}

if [ "$CASSANDRA_BROADCAST_ADDRESS" = 'auto' ]; then
CASSANDRA_BROADCAST_ADDRESS="$(hostname --ip-address)"
CASSANDRA_BROADCAST_ADDRESS="$(_ip_address)"
fi
: ${CASSANDRA_BROADCAST_RPC_ADDRESS:=$CASSANDRA_BROADCAST_ADDRESS}

Expand Down
16 changes: 14 additions & 2 deletions 3.0/docker-entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,30 @@ if [ "$1" = 'cassandra' -a "$(id -u)" = '0' ]; then
exec gosu cassandra "$BASH_SOURCE" "$@"
fi

_ip_address() {
# scrape the first non-localhost IP address of the container
# in Swarm Mode, we often get two IPs -- the container IP, and the (shared) VIP, and the container IP should always be first
ip address | awk '
$1 == "inet" && $2 !~ /^127[.]/ {
gsub(/\/.+$/, "", $2)
print $2
exit
}
'
}

if [ "$1" = 'cassandra' ]; then
: ${CASSANDRA_RPC_ADDRESS='0.0.0.0'}

: ${CASSANDRA_LISTEN_ADDRESS='auto'}
if [ "$CASSANDRA_LISTEN_ADDRESS" = 'auto' ]; then
CASSANDRA_LISTEN_ADDRESS="$(hostname --ip-address)"
CASSANDRA_LISTEN_ADDRESS="$(_ip_address)"
fi

: ${CASSANDRA_BROADCAST_ADDRESS="$CASSANDRA_LISTEN_ADDRESS"}

if [ "$CASSANDRA_BROADCAST_ADDRESS" = 'auto' ]; then
CASSANDRA_BROADCAST_ADDRESS="$(hostname --ip-address)"
CASSANDRA_BROADCAST_ADDRESS="$(_ip_address)"
fi
: ${CASSANDRA_BROADCAST_RPC_ADDRESS:=$CASSANDRA_BROADCAST_ADDRESS}

Expand Down
16 changes: 14 additions & 2 deletions 3.11/docker-entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,30 @@ if [ "$1" = 'cassandra' -a "$(id -u)" = '0' ]; then
exec gosu cassandra "$BASH_SOURCE" "$@"
fi

_ip_address() {
# scrape the first non-localhost IP address of the container
# in Swarm Mode, we often get two IPs -- the container IP, and the (shared) VIP, and the container IP should always be first
ip address | awk '
$1 == "inet" && $2 !~ /^127[.]/ {
gsub(/\/.+$/, "", $2)
print $2
exit
}
'
}

if [ "$1" = 'cassandra' ]; then
: ${CASSANDRA_RPC_ADDRESS='0.0.0.0'}

: ${CASSANDRA_LISTEN_ADDRESS='auto'}
if [ "$CASSANDRA_LISTEN_ADDRESS" = 'auto' ]; then
CASSANDRA_LISTEN_ADDRESS="$(hostname --ip-address)"
CASSANDRA_LISTEN_ADDRESS="$(_ip_address)"
fi

: ${CASSANDRA_BROADCAST_ADDRESS="$CASSANDRA_LISTEN_ADDRESS"}

if [ "$CASSANDRA_BROADCAST_ADDRESS" = 'auto' ]; then
CASSANDRA_BROADCAST_ADDRESS="$(hostname --ip-address)"
CASSANDRA_BROADCAST_ADDRESS="$(_ip_address)"
fi
: ${CASSANDRA_BROADCAST_RPC_ADDRESS:=$CASSANDRA_BROADCAST_ADDRESS}

Expand Down
16 changes: 14 additions & 2 deletions docker-entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,30 @@ if [ "$1" = 'cassandra' -a "$(id -u)" = '0' ]; then
exec gosu cassandra "$BASH_SOURCE" "$@"
fi

_ip_address() {
# scrape the first non-localhost IP address of the container
# in Swarm Mode, we often get two IPs -- the container IP, and the (shared) VIP, and the container IP should always be first
ip address | awk '
$1 == "inet" && $2 !~ /^127[.]/ {
gsub(/\/.+$/, "", $2)
print $2
exit
}
'
}

if [ "$1" = 'cassandra' ]; then
: ${CASSANDRA_RPC_ADDRESS='0.0.0.0'}

: ${CASSANDRA_LISTEN_ADDRESS='auto'}
if [ "$CASSANDRA_LISTEN_ADDRESS" = 'auto' ]; then
CASSANDRA_LISTEN_ADDRESS="$(hostname --ip-address)"
CASSANDRA_LISTEN_ADDRESS="$(_ip_address)"
fi

: ${CASSANDRA_BROADCAST_ADDRESS="$CASSANDRA_LISTEN_ADDRESS"}

if [ "$CASSANDRA_BROADCAST_ADDRESS" = 'auto' ]; then
CASSANDRA_BROADCAST_ADDRESS="$(hostname --ip-address)"
CASSANDRA_BROADCAST_ADDRESS="$(_ip_address)"
fi
: ${CASSANDRA_BROADCAST_RPC_ADDRESS:=$CASSANDRA_BROADCAST_ADDRESS}

Expand Down