Skip to content

Commit 8ff1aa4

Browse files
authored
Merge pull request #443 from infosiftr/unix-socket
Force temporary server to use unix socket only
2 parents 61630eb + f0562fd commit 8ff1aa4

File tree

5 files changed

+40
-25
lines changed

5 files changed

+40
-25
lines changed

3.6/docker-entrypoint.sh

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -141,8 +141,9 @@ _js_escape() {
141141
jq --null-input --arg 'str' "$1" '$str'
142142
}
143143

144-
jsonConfigFile="${TMPDIR:-/tmp}/docker-entrypoint-config.json"
145-
tempConfigFile="${TMPDIR:-/tmp}/docker-entrypoint-temp-config.json"
144+
: "${TMPDIR:=/tmp}"
145+
jsonConfigFile="$TMPDIR/docker-entrypoint-config.json"
146+
tempConfigFile="$TMPDIR/docker-entrypoint-temp-config.json"
146147
_parse_config() {
147148
if [ -s "$tempConfigFile" ]; then
148149
return 0
@@ -260,9 +261,11 @@ if [ "$originalArgOne" = 'mongod' ]; then
260261
if _parse_config "$@"; then
261262
_mongod_hack_ensure_arg_val --config "$tempConfigFile" "${mongodHackedArgs[@]}"
262263
fi
263-
_mongod_hack_ensure_arg_val --bind_ip 127.0.0.1 "${mongodHackedArgs[@]}"
264+
_mongod_hack_ensure_arg_val --bind_ip '' "${mongodHackedArgs[@]}"
264265
_mongod_hack_ensure_arg_val --port 27017 "${mongodHackedArgs[@]}"
266+
_mongod_hack_ensure_arg_val --unixSocketPrefix "$TMPDIR" "${mongodHackedArgs[@]}"
265267
_mongod_hack_ensure_no_arg --bind_ip_all "${mongodHackedArgs[@]}"
268+
_mongod_hack_ensure_no_arg --nounixsocket "${mongodHackedArgs[@]}"
266269

267270
# remove "--auth" and "--replSet" for our initial startup (see https://docs.mongodb.com/manual/tutorial/enable-authentication/#start-mongodb-without-access-control)
268271
# https://github.com/docker-library/mongo/issues/211
@@ -296,13 +299,13 @@ if [ "$originalArgOne" = 'mongod' ]; then
296299
fi
297300
_mongod_hack_ensure_arg --logappend "${mongodHackedArgs[@]}"
298301

299-
pidfile="${TMPDIR:-/tmp}/docker-entrypoint-temp-mongod.pid"
302+
pidfile="$TMPDIR/docker-entrypoint-temp-mongod.pid"
300303
rm -f "$pidfile"
301304
_mongod_hack_ensure_arg_val --pidfilepath "$pidfile" "${mongodHackedArgs[@]}"
302305

303306
"${mongodHackedArgs[@]}" --fork
304307

305-
mongo=( mongo --host 127.0.0.1 --port 27017 --quiet )
308+
mongo=( mongo --host "$TMPDIR/mongodb-27017.sock" --quiet )
306309

307310
# check to see that our "mongod" actually did start up (catches "--help", "--version", MongoDB 3.2 being silly, slow prealloc, etc)
308311
# https://jira.mongodb.org/browse/SERVER-16292

4.0/docker-entrypoint.sh

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -141,8 +141,9 @@ _js_escape() {
141141
jq --null-input --arg 'str' "$1" '$str'
142142
}
143143

144-
jsonConfigFile="${TMPDIR:-/tmp}/docker-entrypoint-config.json"
145-
tempConfigFile="${TMPDIR:-/tmp}/docker-entrypoint-temp-config.json"
144+
: "${TMPDIR:=/tmp}"
145+
jsonConfigFile="$TMPDIR/docker-entrypoint-config.json"
146+
tempConfigFile="$TMPDIR/docker-entrypoint-temp-config.json"
146147
_parse_config() {
147148
if [ -s "$tempConfigFile" ]; then
148149
return 0
@@ -260,9 +261,11 @@ if [ "$originalArgOne" = 'mongod' ]; then
260261
if _parse_config "$@"; then
261262
_mongod_hack_ensure_arg_val --config "$tempConfigFile" "${mongodHackedArgs[@]}"
262263
fi
263-
_mongod_hack_ensure_arg_val --bind_ip 127.0.0.1 "${mongodHackedArgs[@]}"
264+
_mongod_hack_ensure_arg_val --bind_ip '' "${mongodHackedArgs[@]}"
264265
_mongod_hack_ensure_arg_val --port 27017 "${mongodHackedArgs[@]}"
266+
_mongod_hack_ensure_arg_val --unixSocketPrefix "$TMPDIR" "${mongodHackedArgs[@]}"
265267
_mongod_hack_ensure_no_arg --bind_ip_all "${mongodHackedArgs[@]}"
268+
_mongod_hack_ensure_no_arg --nounixsocket "${mongodHackedArgs[@]}"
266269

267270
# remove "--auth" and "--replSet" for our initial startup (see https://docs.mongodb.com/manual/tutorial/enable-authentication/#start-mongodb-without-access-control)
268271
# https://github.com/docker-library/mongo/issues/211
@@ -296,13 +299,13 @@ if [ "$originalArgOne" = 'mongod' ]; then
296299
fi
297300
_mongod_hack_ensure_arg --logappend "${mongodHackedArgs[@]}"
298301

299-
pidfile="${TMPDIR:-/tmp}/docker-entrypoint-temp-mongod.pid"
302+
pidfile="$TMPDIR/docker-entrypoint-temp-mongod.pid"
300303
rm -f "$pidfile"
301304
_mongod_hack_ensure_arg_val --pidfilepath "$pidfile" "${mongodHackedArgs[@]}"
302305

303306
"${mongodHackedArgs[@]}" --fork
304307

305-
mongo=( mongo --host 127.0.0.1 --port 27017 --quiet )
308+
mongo=( mongo --host "$TMPDIR/mongodb-27017.sock" --quiet )
306309

307310
# check to see that our "mongod" actually did start up (catches "--help", "--version", MongoDB 3.2 being silly, slow prealloc, etc)
308311
# https://jira.mongodb.org/browse/SERVER-16292

4.2/docker-entrypoint.sh

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -141,8 +141,9 @@ _js_escape() {
141141
jq --null-input --arg 'str' "$1" '$str'
142142
}
143143

144-
jsonConfigFile="${TMPDIR:-/tmp}/docker-entrypoint-config.json"
145-
tempConfigFile="${TMPDIR:-/tmp}/docker-entrypoint-temp-config.json"
144+
: "${TMPDIR:=/tmp}"
145+
jsonConfigFile="$TMPDIR/docker-entrypoint-config.json"
146+
tempConfigFile="$TMPDIR/docker-entrypoint-temp-config.json"
146147
_parse_config() {
147148
if [ -s "$tempConfigFile" ]; then
148149
return 0
@@ -260,9 +261,11 @@ if [ "$originalArgOne" = 'mongod' ]; then
260261
if _parse_config "$@"; then
261262
_mongod_hack_ensure_arg_val --config "$tempConfigFile" "${mongodHackedArgs[@]}"
262263
fi
263-
_mongod_hack_ensure_arg_val --bind_ip 127.0.0.1 "${mongodHackedArgs[@]}"
264+
_mongod_hack_ensure_arg_val --bind_ip '' "${mongodHackedArgs[@]}"
264265
_mongod_hack_ensure_arg_val --port 27017 "${mongodHackedArgs[@]}"
266+
_mongod_hack_ensure_arg_val --unixSocketPrefix "$TMPDIR" "${mongodHackedArgs[@]}"
265267
_mongod_hack_ensure_no_arg --bind_ip_all "${mongodHackedArgs[@]}"
268+
_mongod_hack_ensure_no_arg --nounixsocket "${mongodHackedArgs[@]}"
266269

267270
# remove "--auth" and "--replSet" for our initial startup (see https://docs.mongodb.com/manual/tutorial/enable-authentication/#start-mongodb-without-access-control)
268271
# https://github.com/docker-library/mongo/issues/211
@@ -296,13 +299,13 @@ if [ "$originalArgOne" = 'mongod' ]; then
296299
fi
297300
_mongod_hack_ensure_arg --logappend "${mongodHackedArgs[@]}"
298301

299-
pidfile="${TMPDIR:-/tmp}/docker-entrypoint-temp-mongod.pid"
302+
pidfile="$TMPDIR/docker-entrypoint-temp-mongod.pid"
300303
rm -f "$pidfile"
301304
_mongod_hack_ensure_arg_val --pidfilepath "$pidfile" "${mongodHackedArgs[@]}"
302305

303306
"${mongodHackedArgs[@]}" --fork
304307

305-
mongo=( mongo --host 127.0.0.1 --port 27017 --quiet )
308+
mongo=( mongo --host "$TMPDIR/mongodb-27017.sock" --quiet )
306309

307310
# check to see that our "mongod" actually did start up (catches "--help", "--version", MongoDB 3.2 being silly, slow prealloc, etc)
308311
# https://jira.mongodb.org/browse/SERVER-16292

4.4/docker-entrypoint.sh

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -141,8 +141,9 @@ _js_escape() {
141141
jq --null-input --arg 'str' "$1" '$str'
142142
}
143143

144-
jsonConfigFile="${TMPDIR:-/tmp}/docker-entrypoint-config.json"
145-
tempConfigFile="${TMPDIR:-/tmp}/docker-entrypoint-temp-config.json"
144+
: "${TMPDIR:=/tmp}"
145+
jsonConfigFile="$TMPDIR/docker-entrypoint-config.json"
146+
tempConfigFile="$TMPDIR/docker-entrypoint-temp-config.json"
146147
_parse_config() {
147148
if [ -s "$tempConfigFile" ]; then
148149
return 0
@@ -260,9 +261,11 @@ if [ "$originalArgOne" = 'mongod' ]; then
260261
if _parse_config "$@"; then
261262
_mongod_hack_ensure_arg_val --config "$tempConfigFile" "${mongodHackedArgs[@]}"
262263
fi
263-
_mongod_hack_ensure_arg_val --bind_ip 127.0.0.1 "${mongodHackedArgs[@]}"
264+
_mongod_hack_ensure_arg_val --bind_ip '' "${mongodHackedArgs[@]}"
264265
_mongod_hack_ensure_arg_val --port 27017 "${mongodHackedArgs[@]}"
266+
_mongod_hack_ensure_arg_val --unixSocketPrefix "$TMPDIR" "${mongodHackedArgs[@]}"
265267
_mongod_hack_ensure_no_arg --bind_ip_all "${mongodHackedArgs[@]}"
268+
_mongod_hack_ensure_no_arg --nounixsocket "${mongodHackedArgs[@]}"
266269

267270
# remove "--auth" and "--replSet" for our initial startup (see https://docs.mongodb.com/manual/tutorial/enable-authentication/#start-mongodb-without-access-control)
268271
# https://github.com/docker-library/mongo/issues/211
@@ -296,13 +299,13 @@ if [ "$originalArgOne" = 'mongod' ]; then
296299
fi
297300
_mongod_hack_ensure_arg --logappend "${mongodHackedArgs[@]}"
298301

299-
pidfile="${TMPDIR:-/tmp}/docker-entrypoint-temp-mongod.pid"
302+
pidfile="$TMPDIR/docker-entrypoint-temp-mongod.pid"
300303
rm -f "$pidfile"
301304
_mongod_hack_ensure_arg_val --pidfilepath "$pidfile" "${mongodHackedArgs[@]}"
302305

303306
"${mongodHackedArgs[@]}" --fork
304307

305-
mongo=( mongo --host 127.0.0.1 --port 27017 --quiet )
308+
mongo=( mongo --host "$TMPDIR/mongodb-27017.sock" --quiet )
306309

307310
# check to see that our "mongod" actually did start up (catches "--help", "--version", MongoDB 3.2 being silly, slow prealloc, etc)
308311
# https://jira.mongodb.org/browse/SERVER-16292

docker-entrypoint.sh

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -141,8 +141,9 @@ _js_escape() {
141141
jq --null-input --arg 'str' "$1" '$str'
142142
}
143143

144-
jsonConfigFile="${TMPDIR:-/tmp}/docker-entrypoint-config.json"
145-
tempConfigFile="${TMPDIR:-/tmp}/docker-entrypoint-temp-config.json"
144+
: "${TMPDIR:=/tmp}"
145+
jsonConfigFile="$TMPDIR/docker-entrypoint-config.json"
146+
tempConfigFile="$TMPDIR/docker-entrypoint-temp-config.json"
146147
_parse_config() {
147148
if [ -s "$tempConfigFile" ]; then
148149
return 0
@@ -260,9 +261,11 @@ if [ "$originalArgOne" = 'mongod' ]; then
260261
if _parse_config "$@"; then
261262
_mongod_hack_ensure_arg_val --config "$tempConfigFile" "${mongodHackedArgs[@]}"
262263
fi
263-
_mongod_hack_ensure_arg_val --bind_ip 127.0.0.1 "${mongodHackedArgs[@]}"
264+
_mongod_hack_ensure_arg_val --bind_ip '' "${mongodHackedArgs[@]}"
264265
_mongod_hack_ensure_arg_val --port 27017 "${mongodHackedArgs[@]}"
266+
_mongod_hack_ensure_arg_val --unixSocketPrefix "$TMPDIR" "${mongodHackedArgs[@]}"
265267
_mongod_hack_ensure_no_arg --bind_ip_all "${mongodHackedArgs[@]}"
268+
_mongod_hack_ensure_no_arg --nounixsocket "${mongodHackedArgs[@]}"
266269

267270
# remove "--auth" and "--replSet" for our initial startup (see https://docs.mongodb.com/manual/tutorial/enable-authentication/#start-mongodb-without-access-control)
268271
# https://github.com/docker-library/mongo/issues/211
@@ -296,13 +299,13 @@ if [ "$originalArgOne" = 'mongod' ]; then
296299
fi
297300
_mongod_hack_ensure_arg --logappend "${mongodHackedArgs[@]}"
298301

299-
pidfile="${TMPDIR:-/tmp}/docker-entrypoint-temp-mongod.pid"
302+
pidfile="$TMPDIR/docker-entrypoint-temp-mongod.pid"
300303
rm -f "$pidfile"
301304
_mongod_hack_ensure_arg_val --pidfilepath "$pidfile" "${mongodHackedArgs[@]}"
302305

303306
"${mongodHackedArgs[@]}" --fork
304307

305-
mongo=( mongo --host 127.0.0.1 --port 27017 --quiet )
308+
mongo=( mongo --host "$TMPDIR/mongodb-27017.sock" --quiet )
306309

307310
# check to see that our "mongod" actually did start up (catches "--help", "--version", MongoDB 3.2 being silly, slow prealloc, etc)
308311
# https://jira.mongodb.org/browse/SERVER-16292

0 commit comments

Comments
 (0)