@@ -206,12 +206,21 @@ _parse_config() {
206
206
cat >&2 " $jsonConfigFile "
207
207
exit 1
208
208
fi
209
- jq ' del(.systemLog, .processManagement, .net, .security, .replication)' " $jsonConfigFile " > " $tempConfigFile "
209
+ jq ' del(.systemLog, .processManagement, .net, .security, .replication, .sharding )' " $jsonConfigFile " > " $tempConfigFile "
210
210
return 0
211
211
fi
212
212
213
213
return 1
214
214
}
215
+
216
+ _isConfigServer () {
217
+ _mongod_hack_have_arg --configsvr " $@ " || {
218
+ _parse_config " $@ " \
219
+ && clusterRole=" $( jq -r ' .sharding.clusterRole // empty' " $jsonConfigFile " ) " \
220
+ && [ " $clusterRole " = ' configsvr' ]
221
+ }
222
+ }
223
+
215
224
dbPath=
216
225
_dbPath () {
217
226
if [ -n " $dbPath " ]; then
@@ -226,11 +235,7 @@ _dbPath() {
226
235
fi
227
236
228
237
if [ -z " $dbPath " ]; then
229
- if _mongod_hack_have_arg --configsvr " $@ " || {
230
- _parse_config " $@ " \
231
- && clusterRole=" $( jq -r ' .sharding.clusterRole // empty' " $jsonConfigFile " ) " \
232
- && [ " $clusterRole " = ' configsvr' ]
233
- }; then
238
+ if _isConfigServer " $@ " ; then
234
239
# if running as config server, then the default dbpath is /data/configdb
235
240
# https://docs.mongodb.com/manual/reference/program/mongod/#cmdoption-mongod-configsvr
236
241
dbPath=/data/configdb
@@ -314,6 +319,12 @@ if [ "$originalArgOne" = 'mongod' ]; then
314
319
if [ " $MONGO_INITDB_ROOT_USERNAME " ] && [ " $MONGO_INITDB_ROOT_PASSWORD " ]; then
315
320
_mongod_hack_ensure_no_arg_val --replSet " ${mongodHackedArgs[@]} "
316
321
fi
322
+ # Setting sharding.clusterRole=configsvr requires the mongod instance to be running with replication
323
+ # disable configsvr for initial startup (https://github.com/docker-library/mongo/issues/509)
324
+ if _isConfigServer " $@ " ; then
325
+ _mongod_hack_ensure_no_arg ' --configsvr' " ${mongodHackedArgs[@]} "
326
+ _mongod_hack_ensure_arg_val ' --dbpath' " $dbPath " " ${mongodHackedArgs[@]} "
327
+ fi
317
328
318
329
# "BadValue: need sslPEMKeyFile when SSL is enabled" vs "BadValue: need to enable SSL via the sslMode flag when using SSL configuration parameters"
319
330
tlsMode=' disabled'
0 commit comments