hackedteam/rcs-db

View on GitHub
bin/rcs-db-mongo-all

Summary

Maintainability
Test Coverage
#!/usr/bin/env ruby

require 'yaml'
require 'rbconfig'

# ensure the working dir is correct
Dir.chdir File.dirname(File.dirname(File.realpath(__FILE__)))

# select the correct dir based upon the platform we are running on
case RbConfig::CONFIG['host_os']
  when /darwin/
    os = 'macos'
    ext = ''
    ulimit = "ulimit -n 1024 &&"
  when /mingw/
    os = 'win'
    ext = '.exe'
    ulimit = ""
end

datadir = Dir.pwd + '/data'
configdir = datadir + '/config'
logdir = Dir.pwd + '/log'

rcs_config = {CN: 'localhost'}
File.open(Dir.pwd + '/config/config.yaml', "r") do |f|
  rcs_config = YAML.load(f.read)
end

# ensure the data directory is present
Dir::mkdir(datadir) if not File.directory?(datadir)
Dir::mkdir(configdir) if not File.directory?(configdir)
Dir::mkdir(logdir) if not File.directory?(logdir)

require_auth = false
keyfile = Dir.pwd + '/config/mongodb.key'

# the mongod executable
mongod = Dir.pwd + '/mongodb/' + os + '/mongod' + ext
mongos = Dir.pwd + '/mongodb/' + os + '/mongos' + ext


puts "Starting the config server (#{rcs_config['CN']})..."
# the config server
parameters = "--dbpath #{configdir} --fork --nssize 64 --logpath #{logdir}/mongoc.log --configsvr --rest --maxConns 1000"
parameters += " --keyFile #{keyfile}" if require_auth
`#{ulimit} #{mongod} #{parameters}`

sleep 1

puts "Starting the shard server..."
# the shard server
parameters = "--dbpath #{datadir} --journal --fork  --nssize 64 --logpath #{logdir}/mongod.log --shardsvr --rest  --maxConns 1000"
parameters += " --keyFile #{keyfile}" if require_auth
`#{ulimit} #{mongod} #{parameters}`

sleep 5

puts "Starting the router..."
# the shard router
parameters = "--logpath #{logdir}/mongos.log --fork --configdb #{rcs_config['CN']}  --maxConns 1000"
parameters += " --keyFile #{keyfile}" if require_auth
`#{ulimit} #{mongos} #{parameters}`