Skip to content

Commit fb13222

Browse files
committed
Fix configsvr with user/pass env vars
1 parent 9223e94 commit fb13222

6 files changed

+102
-36
lines changed

6.0/docker-entrypoint.sh

Lines changed: 17 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

7.0-rc/docker-entrypoint.sh

Lines changed: 17 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

7.0/docker-entrypoint.sh

Lines changed: 17 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

8.0-rc/docker-entrypoint.sh

Lines changed: 17 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

8.0/docker-entrypoint.sh

Lines changed: 17 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docker-entrypoint.sh

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -208,12 +208,21 @@ _parse_config() {
208208
cat >&2 "$jsonConfigFile"
209209
exit 1
210210
fi
211-
jq 'del(.systemLog, .processManagement, .net, .security, .replication)' "$jsonConfigFile" > "$tempConfigFile"
211+
jq 'del(.systemLog, .processManagement, .net, .security, .replication, .sharding)' "$jsonConfigFile" > "$tempConfigFile"
212212
return 0
213213
fi
214214

215215
return 1
216216
}
217+
218+
_isConfigServer() {
219+
_mongod_hack_have_arg --configsvr "$@" || {
220+
_parse_config "$@" \
221+
&& clusterRole="$(jq -r '.sharding.clusterRole // empty' "$jsonConfigFile")" \
222+
&& [ "$clusterRole" = 'configsvr' ]
223+
}
224+
}
225+
217226
dbPath=
218227
_dbPath() {
219228
if [ -n "$dbPath" ]; then
@@ -228,11 +237,7 @@ _dbPath() {
228237
fi
229238

230239
if [ -z "$dbPath" ]; then
231-
if _mongod_hack_have_arg --configsvr "$@" || {
232-
_parse_config "$@" \
233-
&& clusterRole="$(jq -r '.sharding.clusterRole // empty' "$jsonConfigFile")" \
234-
&& [ "$clusterRole" = 'configsvr' ]
235-
}; then
240+
if _isConfigServer "$@"; then
236241
# if running as config server, then the default dbpath is /data/configdb
237242
# https://docs.mongodb.com/manual/reference/program/mongod/#cmdoption-mongod-configsvr
238243
dbPath=/data/configdb
@@ -316,6 +321,12 @@ if [ "$originalArgOne" = 'mongod' ]; then
316321
if [ "$MONGO_INITDB_ROOT_USERNAME" ] && [ "$MONGO_INITDB_ROOT_PASSWORD" ]; then
317322
_mongod_hack_ensure_no_arg_val --replSet "${mongodHackedArgs[@]}"
318323
fi
324+
# Setting sharding.clusterRole=configsvr requires the mongod instance to be running with replication
325+
# disable configsvr for initial startup (https://github.com/docker-library/mongo/issues/509)
326+
if _isConfigServer "$@"; then
327+
_mongod_hack_ensure_no_arg '--configsvr' "${mongodHackedArgs[@]}"
328+
_mongod_hack_ensure_arg_val '--dbpath' "$dbPath" "${mongodHackedArgs[@]}"
329+
fi
319330

320331
# "BadValue: need sslPEMKeyFile when SSL is enabled" vs "BadValue: need to enable SSL via the sslMode flag when using SSL configuration parameters"
321332
tlsMode='disabled'

0 commit comments

Comments
 (0)