Skip to content

Commit c9756da

Browse files
authored
Merge pull request #9 from p-mongo/start-options
Use a structured hash for mongo start options
2 parents 9119d03 + 85d89bb commit c9756da

File tree

3 files changed

+46
-40
lines changed

3 files changed

+46
-40
lines changed

Gemfile

-2
Original file line numberDiff line numberDiff line change
@@ -17,5 +17,3 @@ group :test do
1717
gem 'byebug'
1818
end
1919
end
20-
21-
gem 'mongo', git: 'https://github.com/mongodb/mongo-ruby-driver'

lib/mongo_manager/executor.rb

+45-37
Original file line numberDiff line numberDiff line change
@@ -82,8 +82,8 @@ def start
8282

8383
private def do_start
8484
config[:db_dirs].each do |db_dir|
85-
cmd = config[:settings][db_dir][:start_cmd]
86-
Helper.spawn_mongo(*cmd)
85+
opts = config[:settings][db_dir][:start_options]
86+
Helper.spawn_mongo(**opts)
8787
end
8888
end
8989

@@ -97,7 +97,8 @@ def stop
9797
pids = {}
9898

9999
config[:db_dirs].reverse.each do |db_dir|
100-
binary_basename = File.basename(config[:settings][db_dir][:start_cmd].first)
100+
binary_path = config[:settings][db_dir][:start_options][:bin_path]
101+
binary_basename = File.basename(binary_path)
101102
pid_file_path = File.join(db_dir, "#{binary_basename}.pid")
102103
if File.exist?(pid_file_path)
103104
pid = File.read(pid_file_path).strip.to_i
@@ -130,7 +131,8 @@ def stop
130131
private
131132

132133
def do_wait(db_dir, pid)
133-
binary_basename = File.basename(config[:settings][db_dir][:start_cmd].first)
134+
binary_path = config[:settings][db_dir][:start_options][:bin_path]
135+
binary_basename = File.basename(binary_path)
134136
Helper.wait_for_pid(db_dir, pid, 15, binary_basename)
135137
end
136138

@@ -321,16 +323,18 @@ def init_sharded
321323
dir = root_dir.join("router%02d-#{port}" % mongos)
322324
puts("Spawn mongos on port #{port}")
323325
FileUtils.mkdir(dir)
324-
cmd = [
325-
mongo_path('mongos'),
326-
dir.join('mongos.log').to_s,
327-
dir.join('mongos.pid').to_s,
328-
'--port', port.to_s,
329-
'--configdb', config_db_opt,
330-
] + server_tls_args + common_args +
331-
passthrough_args + (options[:mongos_passthrough_args] || [])
332-
Helper.spawn_mongo(*cmd)
333-
record_start_command(dir, cmd)
326+
opts = {
327+
bin_path: mongo_path('mongos'),
328+
log_path: dir.join('mongos.log').to_s,
329+
pid_file_path: dir.join('mongos.pid').to_s,
330+
args: [
331+
'--port', port.to_s,
332+
'--configdb', config_db_opt,
333+
] + server_tls_args + common_args +
334+
passthrough_args + (options[:mongos_passthrough_args] || []),
335+
}
336+
Helper.spawn_mongo(**opts)
337+
record_start_command(dir, opts)
334338
end
335339

336340
write_config
@@ -582,37 +586,41 @@ def client_tls_options
582586
def spawn_standalone(dir, port, args)
583587
puts("Spawn mongod on port #{port}")
584588
FileUtils.mkdir_p(dir)
585-
cmd = [
586-
mongo_path('mongod'),
587-
dir.join('mongod.log').to_s,
588-
dir.join('mongod.pid').to_s,
589-
'--dbpath', dir.to_s,
590-
'--port', port.to_s,
591-
] + args + server_tls_args + passthrough_args
592-
Helper.spawn_mongo(*cmd)
593-
record_start_command(dir, cmd)
589+
opts = {
590+
bin_path: mongo_path('mongod'),
591+
log_path: dir.join('mongod.log').to_s,
592+
pid_file_path: dir.join('mongod.pid').to_s,
593+
args: [
594+
'--dbpath', dir.to_s,
595+
'--port', port.to_s,
596+
] + args + server_tls_args + passthrough_args,
597+
}
598+
Helper.spawn_mongo(**opts)
599+
record_start_command(dir, opts)
594600
end
595601

596602
def spawn_replica_set_node(dir, port, replica_set_name, args)
597603
puts("Spawn mongod on port #{port}")
598604
FileUtils.mkdir(dir)
599-
cmd = [
600-
mongo_path('mongod'),
601-
dir.join('mongod.log').to_s,
602-
dir.join('mongod.pid').to_s,
603-
'--dbpath', dir.to_s,
604-
'--port', port.to_s,
605-
'--replSet', replica_set_name,
606-
] + args + server_tls_args + passthrough_args
607-
Helper.spawn_mongo(*cmd)
608-
record_start_command(dir, cmd)
609-
end
610-
611-
def record_start_command(dir, cmd)
605+
opts = {
606+
bin_path: mongo_path('mongod'),
607+
log_path: dir.join('mongod.log').to_s,
608+
pid_file_path: dir.join('mongod.pid').to_s,
609+
args: [
610+
'--dbpath', dir.to_s,
611+
'--port', port.to_s,
612+
'--replSet', replica_set_name,
613+
] + args + server_tls_args + passthrough_args,
614+
}
615+
Helper.spawn_mongo(**opts)
616+
record_start_command(dir, opts)
617+
end
618+
619+
def record_start_command(dir, opts)
612620
dir = dir.to_s
613621
config[:settings] ||= {}
614622
config[:settings][dir] ||= {}
615-
config[:settings][dir][:start_cmd] = cmd
623+
config[:settings][dir][:start_options] = opts
616624
config[:db_dirs] << dir unless config[:db_dirs].include?(dir)
617625
end
618626

lib/mongo_manager/helper.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ def spawn(cmd)
1313
end
1414
end
1515

16-
def spawn_mongo(bin_path, log_path, pid_file_path, *args)
16+
def spawn_mongo(bin_path:, log_path:, pid_file_path:, args:)
1717
expanded_cmd = [
1818
bin_path,
1919
'--logpath', log_path,

0 commit comments

Comments
 (0)