mondupe 0.0.16 → 0.0.17
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/bin/mondupe +11 -0
- data/lib/mondupe.rb +10 -0
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 76a46f83862e1b3a96d2731f875b373a251f1a3a
|
4
|
+
data.tar.gz: f3d8d5c03a12633fbeb4cff474df37a8dc0a147c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 111faa887abb9121adf473445303a46201586dc483c4b2d5aea257be96e94638aa8ac03427a4aa3aaef5913e4471167a1f7332bd7bfab4ec3ffe0e8686b2c730
|
7
|
+
data.tar.gz: 7308ce51eeee098c3a212bbf3f0c80d4b08c579724ba338ee3b3bc7ffe095988b3ccff39cabf03b8a07f7392dea668dd8651a5b04604c98d8c5e0f8a9fb496d6
|
data/bin/mondupe
CHANGED
@@ -23,6 +23,9 @@ opt_parser = OptionParser.new do |opt|
|
|
23
23
|
opt.separator " restore - Restore a mongo dump that exists on a host"
|
24
24
|
opt.separator " Requires -n [name] -a [ipaddress]"
|
25
25
|
opt.separator " Optional -t [tmpdir] -u [mongo_username] -p [mongo_password] -c [mongo_authdb]"
|
26
|
+
opt.separator " execute - Execute some java script against database"
|
27
|
+
opt.separator " Requires -n [name] -a [dns_address] -x '[javascript]'"
|
28
|
+
opt.separator " Optional -r [db_name]"
|
26
29
|
opt.separator " expire - (coming soon) Reset the expiration days of a node"
|
27
30
|
opt.separator " Requires ( -n [name] || -d [id] || -a [ipaddress] ) -e [expire_days]"
|
28
31
|
opt.separator " list - (coming soon) List all mongo hosts."
|
@@ -86,6 +89,10 @@ opt_parser = OptionParser.new do |opt|
|
|
86
89
|
$options[:mongo_auth_db] = mongo_auth_db
|
87
90
|
end
|
88
91
|
|
92
|
+
opt.on("-x","--execute","Java Script to execute against DB") do |java_string|
|
93
|
+
$options[:java_string] = java_string
|
94
|
+
end
|
95
|
+
|
89
96
|
opt.on("-h","--help","help") do
|
90
97
|
puts opt_parser
|
91
98
|
end
|
@@ -129,6 +136,7 @@ mongo_db_name = $options[:mongo_db_name] || ENV['MONDUPE_MONGO_DB_NAME'] || nil
|
|
129
136
|
mongo_user = $options[:mongo_user] || ENV['MONDUPE_MONGO_USER'] || nil
|
130
137
|
mongo_pass = $options[:mongo_pass] || ENV['MONDUPE_MONGO_PASS'] || nil
|
131
138
|
mongo_auth_db = $options[:mongo_auth_db] || ENV['MONDUPE_MONGO_AUTH_DB'] || nil
|
139
|
+
java_string = $options[:java_string] || nil
|
132
140
|
instance_count = 1
|
133
141
|
chef_run_list = ENV['MONDUPE_CHEF_RUN_LIST'] || ""
|
134
142
|
chef_environment = ENV['MONDUPE_CHEF_ENVIRONMENT'] || "default"
|
@@ -167,6 +175,9 @@ when "dumps3"
|
|
167
175
|
when "restore"
|
168
176
|
puts "Restoring mongo database from dump"
|
169
177
|
Mondupe.new.restore_db(instance_ipaddress, dump_tmp_path, ssh_key, ssh_user, dump_file_name, mongo_db_name, mongo_user, mongo_pass, mongo_auth_db)
|
178
|
+
when 'execute'
|
179
|
+
puts "Executing JS against database"
|
180
|
+
Mondupe.new.execute_js(instance_ipaddress, ssh_key, ssh_user, java_string, mongo_db_name, mongo_user, mongo_pass, mongo_auth_db)
|
170
181
|
when "terminate"
|
171
182
|
puts "Marking instance for termination"
|
172
183
|
Mondupe.new.terminate_instance(instance_id)
|
data/lib/mondupe.rb
CHANGED
@@ -148,6 +148,16 @@ class Mondupe
|
|
148
148
|
if $?.success? then puts "#{Time.now.to_s} - Mess cleaned up!" else abort("Error cleaning up after myself...") end
|
149
149
|
end
|
150
150
|
|
151
|
+
def execute_js(instance_dns, ssh_key, ssh_user, java_command, mongo_db_name, mongo_user, mongo_pass, mongo_auth_db)
|
152
|
+
abort "You must specify a database name to execute java script against. Use -n [name] or ENV['MONGO_DB_NAME'] to set this value." if mongo_db_name.nil?
|
153
|
+
db_connect_string = "mongo #{mongo_db_name}"
|
154
|
+
db_connect_string << " -u \"#{mongo_user}\" -p \"#{mongo_pass}\"" if !mongo_user.nil? && !mongo_pass.nil?
|
155
|
+
db_connect_string << " --authenticationDatabase \"#{mongo_auth_db}\"" if !mongo_auth_db.nil?
|
156
|
+
puts "#{Time.now.to_s} - Running command against #{mongo_db_name}"
|
157
|
+
`ssh -i #{ssh_key} #{ssh_user}@#{instance_dns} "echo '#{java_command}' | #{db_connect_string}"`
|
158
|
+
if $?.success? then puts "#{Time.now.to_s} - Command execution complete" else abort("Error executing command") end
|
159
|
+
end
|
160
|
+
|
151
161
|
def terminate(instance_id)
|
152
162
|
puts "function not quite ready yet"
|
153
163
|
end
|