Skip to content

Commit

Permalink
Adjust "sed" expressions so we can bind-mount the configuration file
Browse files Browse the repository at this point in the history
This allows the file to be rewritten in-place even in the face of a bind mount (assuming permissions, etc).
  • Loading branch information
tianon committed Oct 1, 2018
1 parent 9182976 commit 4096dee
Show file tree
Hide file tree
Showing 5 changed files with 85 additions and 20 deletions.
21 changes: 17 additions & 4 deletions 2.1/docker-entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,16 @@ _ip_address() {
'
}

# "sed -i", but without "mv" (which doesn't work on a bind-mounted file, for example)
_sed-in-place() {
local filename="$1"; shift
local tempFile
tempFile="$(mktemp)"
sed "$@" "$filename" > "$tempFile"
cat "$tempFile" > "$filename"
rm "$tempFile"
}

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

Expand All @@ -44,8 +54,9 @@ if [ "$1" = 'cassandra' ]; then
: ${CASSANDRA_SEEDS:="cassandra"}
fi
: ${CASSANDRA_SEEDS:="$CASSANDRA_BROADCAST_ADDRESS"}

sed -ri 's/(- seeds:).*/\1 "'"$CASSANDRA_SEEDS"'"/' "$CASSANDRA_CONFIG/cassandra.yaml"

_sed-in-place "$CASSANDRA_CONFIG/cassandra.yaml" \
-r 's/(- seeds:).*/\1 "'"$CASSANDRA_SEEDS"'"/'

for yaml in \
broadcast_address \
Expand All @@ -60,15 +71,17 @@ if [ "$1" = 'cassandra' ]; then
var="CASSANDRA_${yaml^^}"
val="${!var}"
if [ "$val" ]; then
sed -ri 's/^(# )?('"$yaml"':).*/\2 '"$val"'/' "$CASSANDRA_CONFIG/cassandra.yaml"
_sed-in-place "$CASSANDRA_CONFIG/cassandra.yaml" \
-r 's/^(# )?('"$yaml"':).*/\2 '"$val"'/'
fi
done

for rackdc in dc rack; do
var="CASSANDRA_${rackdc^^}"
val="${!var}"
if [ "$val" ]; then
sed -ri 's/^('"$rackdc"'=).*/\1 '"$val"'/' "$CASSANDRA_CONFIG/cassandra-rackdc.properties"
_sed-in-place "$CASSANDRA_CONFIG/cassandra-rackdc.properties" \
-r 's/^('"$rackdc"'=).*/\1 '"$val"'/'
fi
done
fi
Expand Down
21 changes: 17 additions & 4 deletions 2.2/docker-entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,16 @@ _ip_address() {
'
}

# "sed -i", but without "mv" (which doesn't work on a bind-mounted file, for example)
_sed-in-place() {
local filename="$1"; shift
local tempFile
tempFile="$(mktemp)"
sed "$@" "$filename" > "$tempFile"
cat "$tempFile" > "$filename"
rm "$tempFile"
}

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

Expand All @@ -44,8 +54,9 @@ if [ "$1" = 'cassandra' ]; then
: ${CASSANDRA_SEEDS:="cassandra"}
fi
: ${CASSANDRA_SEEDS:="$CASSANDRA_BROADCAST_ADDRESS"}

sed -ri 's/(- seeds:).*/\1 "'"$CASSANDRA_SEEDS"'"/' "$CASSANDRA_CONFIG/cassandra.yaml"

_sed-in-place "$CASSANDRA_CONFIG/cassandra.yaml" \
-r 's/(- seeds:).*/\1 "'"$CASSANDRA_SEEDS"'"/'

for yaml in \
broadcast_address \
Expand All @@ -60,15 +71,17 @@ if [ "$1" = 'cassandra' ]; then
var="CASSANDRA_${yaml^^}"
val="${!var}"
if [ "$val" ]; then
sed -ri 's/^(# )?('"$yaml"':).*/\2 '"$val"'/' "$CASSANDRA_CONFIG/cassandra.yaml"
_sed-in-place "$CASSANDRA_CONFIG/cassandra.yaml" \
-r 's/^(# )?('"$yaml"':).*/\2 '"$val"'/'
fi
done

for rackdc in dc rack; do
var="CASSANDRA_${rackdc^^}"
val="${!var}"
if [ "$val" ]; then
sed -ri 's/^('"$rackdc"'=).*/\1 '"$val"'/' "$CASSANDRA_CONFIG/cassandra-rackdc.properties"
_sed-in-place "$CASSANDRA_CONFIG/cassandra-rackdc.properties" \
-r 's/^('"$rackdc"'=).*/\1 '"$val"'/'
fi
done
fi
Expand Down
21 changes: 17 additions & 4 deletions 3.0/docker-entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,16 @@ _ip_address() {
'
}

# "sed -i", but without "mv" (which doesn't work on a bind-mounted file, for example)
_sed-in-place() {
local filename="$1"; shift
local tempFile
tempFile="$(mktemp)"
sed "$@" "$filename" > "$tempFile"
cat "$tempFile" > "$filename"
rm "$tempFile"
}

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

Expand All @@ -44,8 +54,9 @@ if [ "$1" = 'cassandra' ]; then
: ${CASSANDRA_SEEDS:="cassandra"}
fi
: ${CASSANDRA_SEEDS:="$CASSANDRA_BROADCAST_ADDRESS"}

sed -ri 's/(- seeds:).*/\1 "'"$CASSANDRA_SEEDS"'"/' "$CASSANDRA_CONFIG/cassandra.yaml"

_sed-in-place "$CASSANDRA_CONFIG/cassandra.yaml" \
-r 's/(- seeds:).*/\1 "'"$CASSANDRA_SEEDS"'"/'

for yaml in \
broadcast_address \
Expand All @@ -60,15 +71,17 @@ if [ "$1" = 'cassandra' ]; then
var="CASSANDRA_${yaml^^}"
val="${!var}"
if [ "$val" ]; then
sed -ri 's/^(# )?('"$yaml"':).*/\2 '"$val"'/' "$CASSANDRA_CONFIG/cassandra.yaml"
_sed-in-place "$CASSANDRA_CONFIG/cassandra.yaml" \
-r 's/^(# )?('"$yaml"':).*/\2 '"$val"'/'
fi
done

for rackdc in dc rack; do
var="CASSANDRA_${rackdc^^}"
val="${!var}"
if [ "$val" ]; then
sed -ri 's/^('"$rackdc"'=).*/\1 '"$val"'/' "$CASSANDRA_CONFIG/cassandra-rackdc.properties"
_sed-in-place "$CASSANDRA_CONFIG/cassandra-rackdc.properties" \
-r 's/^('"$rackdc"'=).*/\1 '"$val"'/'
fi
done
fi
Expand Down
21 changes: 17 additions & 4 deletions 3.11/docker-entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,16 @@ _ip_address() {
'
}

# "sed -i", but without "mv" (which doesn't work on a bind-mounted file, for example)
_sed-in-place() {
local filename="$1"; shift
local tempFile
tempFile="$(mktemp)"
sed "$@" "$filename" > "$tempFile"
cat "$tempFile" > "$filename"
rm "$tempFile"
}

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

Expand All @@ -44,8 +54,9 @@ if [ "$1" = 'cassandra' ]; then
: ${CASSANDRA_SEEDS:="cassandra"}
fi
: ${CASSANDRA_SEEDS:="$CASSANDRA_BROADCAST_ADDRESS"}

sed -ri 's/(- seeds:).*/\1 "'"$CASSANDRA_SEEDS"'"/' "$CASSANDRA_CONFIG/cassandra.yaml"

_sed-in-place "$CASSANDRA_CONFIG/cassandra.yaml" \
-r 's/(- seeds:).*/\1 "'"$CASSANDRA_SEEDS"'"/'

for yaml in \
broadcast_address \
Expand All @@ -60,15 +71,17 @@ if [ "$1" = 'cassandra' ]; then
var="CASSANDRA_${yaml^^}"
val="${!var}"
if [ "$val" ]; then
sed -ri 's/^(# )?('"$yaml"':).*/\2 '"$val"'/' "$CASSANDRA_CONFIG/cassandra.yaml"
_sed-in-place "$CASSANDRA_CONFIG/cassandra.yaml" \
-r 's/^(# )?('"$yaml"':).*/\2 '"$val"'/'
fi
done

for rackdc in dc rack; do
var="CASSANDRA_${rackdc^^}"
val="${!var}"
if [ "$val" ]; then
sed -ri 's/^('"$rackdc"'=).*/\1 '"$val"'/' "$CASSANDRA_CONFIG/cassandra-rackdc.properties"
_sed-in-place "$CASSANDRA_CONFIG/cassandra-rackdc.properties" \
-r 's/^('"$rackdc"'=).*/\1 '"$val"'/'
fi
done
fi
Expand Down
21 changes: 17 additions & 4 deletions docker-entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,16 @@ _ip_address() {
'
}

# "sed -i", but without "mv" (which doesn't work on a bind-mounted file, for example)
_sed-in-place() {
local filename="$1"; shift
local tempFile
tempFile="$(mktemp)"
sed "$@" "$filename" > "$tempFile"
cat "$tempFile" > "$filename"
rm "$tempFile"
}

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

Expand All @@ -44,8 +54,9 @@ if [ "$1" = 'cassandra' ]; then
: ${CASSANDRA_SEEDS:="cassandra"}
fi
: ${CASSANDRA_SEEDS:="$CASSANDRA_BROADCAST_ADDRESS"}

sed -ri 's/(- seeds:).*/\1 "'"$CASSANDRA_SEEDS"'"/' "$CASSANDRA_CONFIG/cassandra.yaml"

_sed-in-place "$CASSANDRA_CONFIG/cassandra.yaml" \
-r 's/(- seeds:).*/\1 "'"$CASSANDRA_SEEDS"'"/'

for yaml in \
broadcast_address \
Expand All @@ -60,15 +71,17 @@ if [ "$1" = 'cassandra' ]; then
var="CASSANDRA_${yaml^^}"
val="${!var}"
if [ "$val" ]; then
sed -ri 's/^(# )?('"$yaml"':).*/\2 '"$val"'/' "$CASSANDRA_CONFIG/cassandra.yaml"
_sed-in-place "$CASSANDRA_CONFIG/cassandra.yaml" \
-r 's/^(# )?('"$yaml"':).*/\2 '"$val"'/'
fi
done

for rackdc in dc rack; do
var="CASSANDRA_${rackdc^^}"
val="${!var}"
if [ "$val" ]; then
sed -ri 's/^('"$rackdc"'=).*/\1 '"$val"'/' "$CASSANDRA_CONFIG/cassandra-rackdc.properties"
_sed-in-place "$CASSANDRA_CONFIG/cassandra-rackdc.properties" \
-r 's/^('"$rackdc"'=).*/\1 '"$val"'/'
fi
done
fi
Expand Down

0 comments on commit 4096dee

Please sign in to comment.