mongolly 0.2.0 → 0.2.1
Sign up to get free protection for your applications and to get access to all the features.
- data/bin/mongolly +2 -1
- data/lib/mongolly/extensions/mongo/mongo_client.rb +31 -60
- data/lib/mongolly/version.rb +1 -1
- metadata +2 -2
data/bin/mongolly
CHANGED
@@ -20,7 +20,8 @@ class Mongo::MongoClient
|
|
20
20
|
if mongos?
|
21
21
|
@mongolly_logger.info("Detected sharded cluster")
|
22
22
|
with_disabled_balancing do
|
23
|
-
|
23
|
+
# Stop Config Server
|
24
|
+
ssh_command(options[:config_server_ssh_user], config_server, options[:mongo_stop_command], options[:config_server_ssh_keypath])
|
24
25
|
|
25
26
|
backup_instance(config_server, options, false)
|
26
27
|
|
@@ -28,7 +29,8 @@ class Mongo::MongoClient
|
|
28
29
|
@mongolly_logger.debug("Found Shard #{name} with hosts #{hosts}.")
|
29
30
|
replica_set_connection(hosts, options).snapshot_ebs(options)
|
30
31
|
end
|
31
|
-
|
32
|
+
# Start Config Server
|
33
|
+
ssh_command(options[:config_server_ssh_user], config_server, options[:mongo_start_command], options[:config_server_ssh_keypath])
|
32
34
|
end
|
33
35
|
else
|
34
36
|
backup_instance(snapshot_ebs_target, options, true )
|
@@ -89,64 +91,6 @@ protected
|
|
89
91
|
self['config'].collection('locks').find({_id: 'balancer'}).count > 1
|
90
92
|
end
|
91
93
|
|
92
|
-
def stop_config_server(user, stop_command)
|
93
|
-
raise RuntimeError.new "mongo ssh user not specified" unless user.to_s.strip != ''
|
94
|
-
raise RuntimeError.new "mongo ssh user not specified" unless stop_command.to_s.strip != ''
|
95
|
-
@mongolly_logger.debug "Stopping config server #{config_server}"
|
96
|
-
unless @mongolly_dry_run
|
97
|
-
exit_code = nil
|
98
|
-
output = ''
|
99
|
-
Net::SSH.start(config_server, user.strip) do |ssh|
|
100
|
-
channel = ssh.open_channel do |ch|
|
101
|
-
ch.request_pty
|
102
|
-
ch.exec(stop_command.strip) do |ch, success|
|
103
|
-
raise "Unable to stop config server on #{config_server}" unless success
|
104
|
-
end
|
105
|
-
end
|
106
|
-
channel.on_request("exit-status") do |ch,data|
|
107
|
-
exit_code = data.read_long
|
108
|
-
end
|
109
|
-
channel.on_extended_data do |ch,type,data|
|
110
|
-
output += data
|
111
|
-
end
|
112
|
-
ssh.loop
|
113
|
-
end
|
114
|
-
|
115
|
-
if exit_code != 0
|
116
|
-
raise RuntimeError.new "Unable to stop config server, #{output}"
|
117
|
-
end
|
118
|
-
end
|
119
|
-
end
|
120
|
-
|
121
|
-
def start_config_server(user, start_command )
|
122
|
-
raise RuntimeError.new "mongo ssh user not specified" unless user.to_s.strip != ''
|
123
|
-
raise RuntimeError.new "mongo ssh user not specified" unless start_command.to_s.strip != ''
|
124
|
-
@mongolly_logger.debug "Starting config server #{config_server}"
|
125
|
-
unless @mongolly_dry_run
|
126
|
-
exit_code = nil
|
127
|
-
output = ''
|
128
|
-
Net::SSH.start(config_server, user.strip) do |ssh|
|
129
|
-
channel = ssh.open_channel do |ch|
|
130
|
-
ch.request_pty
|
131
|
-
ch.exec(start_command.strip) do |ch, success|
|
132
|
-
raise "Unable to start config server on #{config_server}" unless success
|
133
|
-
end
|
134
|
-
end
|
135
|
-
channel.on_request("exit-status") do |ch,data|
|
136
|
-
exit_code = data.read_long
|
137
|
-
end
|
138
|
-
channel.on_extended_data do |ch,type,data|
|
139
|
-
output += data
|
140
|
-
end
|
141
|
-
ssh.loop
|
142
|
-
end
|
143
|
-
|
144
|
-
if exit_code != 0
|
145
|
-
raise RuntimeError.new "Unable to start config server, #{output}"
|
146
|
-
end
|
147
|
-
end
|
148
|
-
end
|
149
|
-
|
150
94
|
def config_server
|
151
95
|
unless @config_server
|
152
96
|
@config_server = self['admin'].command( { getCmdLineOpts: 1 } )["parsed"]["configdb"].split(",").sort.first.split(":").first
|
@@ -239,4 +183,31 @@ protected
|
|
239
183
|
return db
|
240
184
|
end
|
241
185
|
|
186
|
+
def ssh_command(user, host, command, keypath = nil)
|
187
|
+
@mongolly_logger.debug("Running #{command} on #{host} as #{user}")
|
188
|
+
return if @mongolly_dry_run
|
189
|
+
exit_code = nil
|
190
|
+
output = ''
|
191
|
+
Net::SSH.start(host, user.strip, keys: keypath) do |ssh|
|
192
|
+
channel = ssh.open_channel do |ch|
|
193
|
+
ch.request_pty
|
194
|
+
ch.exec(command.strip) do |ch, success|
|
195
|
+
raise "Unable to exec #{command.strip} on #{host}" unless success
|
196
|
+
end
|
197
|
+
end
|
198
|
+
channel.on_request("exit-status") do |ch,data|
|
199
|
+
exit_code = data.read_long
|
200
|
+
end
|
201
|
+
channel.on_extended_data do |ch,type,data|
|
202
|
+
output += data
|
203
|
+
end
|
204
|
+
ssh.loop
|
205
|
+
end
|
206
|
+
|
207
|
+
if exit_code != 0
|
208
|
+
raise RuntimeError.new "Unable to exec #{command} on #{host}, #{output}"
|
209
|
+
end
|
210
|
+
end
|
211
|
+
|
212
|
+
|
242
213
|
end
|
data/lib/mongolly/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mongolly
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.1
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-05-
|
12
|
+
date: 2013-05-30 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: thor
|