6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
|
# File 'lib/danarchy_deploy/services/mongodb.rb', line 6
def self.new(os, mongodb, options)
@mongodb = mongodb
@options = options
puts "\n" + self.name
puts "\n > Configuring MongoDB service."
DanarchyDeploy::Services::Init.init_manager(os, 'mongodb', 'start', options) if ! options[:pretend]
Mongo::Logger.logger.level = Logger::FATAL
mongodb_conf, updated_conf = self.load_mongodb_conf
host_port = mongodb_conf['net']['bindIp'].split(',').first + ':' + mongodb_conf['net']['port'].to_s
admin_user, new_admin = self.load_admin_user
if new_admin == true
client = Mongo::Client.new(['127.0.0.1'], database: 'admin')
self.ensure_user(client.database, admin_user)
end
if ! options[:pretend] && updated_conf == true || new_admin == true
puts 'Stopping MongoDB'
DanarchyDeploy::Services::Init.init_manager(os, 'mongodb', 'stop', options)
self.save_mongodb_conf(mongodb_conf)
puts 'Starting MongoDB'
DanarchyDeploy::Services::Init.init_manager(os, 'mongodb', 'start', options)
end
client = Mongo::Client.new([host_port], database: 'admin',
user: admin_user[:user], password: Base64.decode64(admin_user[:password]))
self.ensure_user(client.database, admin_user)
if databases = @mongodb[:databases]
databases.each do |database, params|
print "\n |+ Fake Run: " if options[:pretend]
puts "\n Reviewing database: #{database}"
db = client.use(database).database
params[:users].each do |user|
puts " > Checking user: #{user[:user]}"
self.ensure_user(db, user)
end
end
end
end
|