@@ -129,15 +129,8 @@ def read_config
129
129
end
130
130
131
131
def init_standalone
132
- cmd = [
133
- mongo_path ( 'mongod' ) ,
134
- root_dir . join ( 'mongod.log' ) . to_s ,
135
- root_dir . join ( 'mongod.pid' ) . to_s ,
136
- '--dbpath' , root_dir . to_s ,
137
- '--port' , base_port . to_s ,
138
- ] + server_tls_args + ( options [ :mongod_passthrough_args ] || [ ] ) + passthrough_args
139
- Helper . spawn_mongo ( *cmd )
140
- record_start_command ( root_dir , cmd )
132
+ dir = root_dir . join ( 'standalone' )
133
+ spawn_standalone ( dir , base_port , [ ] )
141
134
142
135
if options [ :username ]
143
136
client = Mongo ::Client . new ( [ "localhost:#{ base_port } " ] ,
@@ -148,12 +141,9 @@ def init_standalone
148
141
149
142
do_stop
150
143
151
- cmd << '--auth'
152
-
153
- Helper . spawn_mongo ( *cmd )
144
+ spawn_standalone ( dir , base_port , %w( --auth ) )
154
145
end
155
146
156
- record_start_command ( root_dir , cmd )
157
147
write_config
158
148
end
159
149
@@ -202,14 +192,18 @@ def init_rs
202
192
def init_sharded
203
193
maybe_create_key
204
194
205
- spawn_replica_set_node (
206
- root_dir . join ( 'csrs' ) ,
207
- base_port + num_mongos ,
208
- 'csrs' ,
209
- common_args + %w( --configsvr ) ,
210
- )
195
+ if config [ :csrs ]
196
+ spawn_replica_set_node (
197
+ root_dir . join ( 'csrs' ) ,
198
+ base_port + num_mongos ,
199
+ 'csrs' ,
200
+ common_args + %w( --configsvr ) ,
201
+ )
211
202
212
- initiate_replica_set ( %W( localhost:#{ base_port +num_mongos } ) , 'csrs' , configsvr : true )
203
+ initiate_replica_set ( %W( localhost:#{ base_port +num_mongos } ) , 'csrs' , configsvr : true )
204
+ else
205
+ spawn_standalone ( root_dir . join ( 'csrs' ) , base_port + num_mongos , %w( --configsvr ) )
206
+ end
213
207
214
208
shard_base_port = base_port + num_mongos + 1
215
209
@@ -226,6 +220,12 @@ def init_sharded
226
220
initiate_replica_set ( %W( localhost:#{ port } ) , shard_name )
227
221
end
228
222
223
+ config_db_opt = if options [ :csrs ]
224
+ "csrs/localhost:#{ base_port +num_mongos } "
225
+ else
226
+ "localhost:#{ base_port +num_mongos } "
227
+ end
228
+
229
229
1 . upto ( num_mongos ) do |mongos |
230
230
port = base_port - 1 + mongos
231
231
dir = root_dir . join ( 'router%02d' % mongos )
@@ -236,7 +236,7 @@ def init_sharded
236
236
dir . join ( 'mongos.log' ) . to_s ,
237
237
dir . join ( 'mongos.pid' ) . to_s ,
238
238
'--port' , port . to_s ,
239
- '--configdb' , "csrs/localhost: #{ base_port + num_mongos } " ,
239
+ '--configdb' , config_db_opt ,
240
240
] + server_tls_args + common_args +
241
241
passthrough_args + ( options [ :mongos_passthrough_args ] || [ ] )
242
242
Helper . spawn_mongo ( *cmd )
@@ -422,6 +422,21 @@ def client_tls_options
422
422
end . freeze
423
423
end
424
424
425
+ def spawn_standalone ( dir , port , args )
426
+ puts ( "Spawn mongod on port #{ port } " )
427
+ FileUtils . mkdir_p ( dir )
428
+ cmd = [
429
+ mongo_path ( 'mongod' ) ,
430
+ dir . join ( 'mongod.log' ) . to_s ,
431
+ dir . join ( 'mongod.pid' ) . to_s ,
432
+ '--dbpath' , dir . to_s ,
433
+ '--port' , port . to_s ,
434
+ ] + args + server_tls_args +
435
+ ( options [ :mongod_passthrough_args ] || [ ] ) + passthrough_args
436
+ Helper . spawn_mongo ( *cmd )
437
+ record_start_command ( dir , cmd )
438
+ end
439
+
425
440
def spawn_replica_set_node ( dir , port , replica_set_name , args )
426
441
puts ( "Spawn mongod on port #{ port } " )
427
442
FileUtils . mkdir ( dir )
0 commit comments