@@ -206,12 +206,21 @@ _parse_config() {
206206 cat >&2 " $jsonConfigFile "
207207 exit 1
208208 fi
209- jq ' del(.systemLog, .processManagement, .net, .security, .replication)' " $jsonConfigFile " > " $tempConfigFile "
209+ jq ' del(.systemLog, .processManagement, .net, .security, .replication, .sharding )' " $jsonConfigFile " > " $tempConfigFile "
210210 return 0
211211 fi
212212
213213 return 1
214214}
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+
215224dbPath=
216225_dbPath () {
217226 if [ -n " $dbPath " ]; then
@@ -226,11 +235,7 @@ _dbPath() {
226235 fi
227236
228237 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
234239 # if running as config server, then the default dbpath is /data/configdb
235240 # https://docs.mongodb.com/manual/reference/program/mongod/#cmdoption-mongod-configsvr
236241 dbPath=/data/configdb
@@ -314,6 +319,12 @@ if [ "$originalArgOne" = 'mongod' ]; then
314319 if [ " $MONGO_INITDB_ROOT_USERNAME " ] && [ " $MONGO_INITDB_ROOT_PASSWORD " ]; then
315320 _mongod_hack_ensure_no_arg_val --replSet " ${mongodHackedArgs[@]} "
316321 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
317328
318329 # "BadValue: need sslPEMKeyFile when SSL is enabled" vs "BadValue: need to enable SSL via the sslMode flag when using SSL configuration parameters"
319330 tlsMode=' disabled'
0 commit comments