mondupe 0.0.34 → 0.0.35

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.
Files changed (4) hide show
  1. checksums.yaml +4 -4
  2. data/bin/mondupe +1 -0
  3. data/lib/mondupe.rb +15 -19
  4. metadata +1 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: bf37972e592daef1fd97f2983ce65c7a15f88bfd
4
- data.tar.gz: 3fb5c14ccb04b8499896e16961594e0211d8dc33
3
+ metadata.gz: 09d1178f6114f5753a0085ebd2cb18b9a00002fd
4
+ data.tar.gz: 13ab96c86ca846ff06af27e71bbecad50acaaa2f
5
5
  SHA512:
6
- metadata.gz: 52a6896ee4c9eed48d5741b932da09ae882f7872789744adba4d1e148b04242f32519a08c03e48cf467ad40712e9c64a845377fa76b9620d5ef03dd63a674a89
7
- data.tar.gz: 1a8a7d6ec18aaaaef258a05a7af40caae96782923756d6ccbdb0dbf07163e85aaf2d563a062f21b07afb3043c88370f0b24d1e1b4144707dff34a5b479dba1d3
6
+ metadata.gz: 1ab3b7c62aeb7cabbb332da35483ea1d695014c5d6abba1f218c3b1c86c87fc011f2dfd983b60b14ac01dd8f97ca236a360f3203236c69e323649dfcf9a3c2bd
7
+ data.tar.gz: 725e2f6dfdf4fb4f8bc60a3cb67dbbe37bece5ecad4251028170d7092e25a99a48f75d9666e1a1a345976f9cbece8ae83e0ab92593ad5e004e94e4fcd1642584
data/bin/mondupe CHANGED
@@ -95,6 +95,7 @@ opt_parser = OptionParser.new do |opt|
95
95
 
96
96
  opt.on("-h","--help","help") do
97
97
  puts opt_parser
98
+ exit
98
99
  end
99
100
 
100
101
  opt.separator "Environment Variables - Set these in your environment. They should be self explanitory."
data/lib/mondupe.rb CHANGED
@@ -86,21 +86,25 @@ class Mondupe
86
86
  end
87
87
  end
88
88
 
89
+ def try_command(tries, command)
90
+ begin
91
+ `#{command}` or raise "Failure"
92
+ rescue
93
+ tries -= 1
94
+ if tries > 0
95
+ puts "Trying again. #{tries} left."
96
+ retry
97
+ end
98
+ puts "Failed after #{tries} retries..."
99
+ end
100
+ end
89
101
 
90
102
  def bootstrap(instance_name, instance_fqdn, instance_ipaddress, chef_environment, chef_identity_file, chef_run_list, ssh_user, knife_exec)
91
103
  # Bootstrap the new instance with chef
92
104
  puts "Bootstraping node with Chef..."
93
105
  puts "Running..."
94
106
  #puts "#{knife_exec} bootstrap #{instance_ipaddress} -N #{instance_fqdn[0...-1]} -E #{chef_environment} -i #{chef_identity_file} -r #{chef_run_list} -x #{ssh_user} --sudo"
95
- tries = 20
96
- begin
97
- sleep 30
98
- system("#{knife_exec} bootstrap #{instance_ipaddress} -N #{instance_fqdn[0...-1]} -E #{chef_environment} -i #{chef_identity_file} -r #{chef_run_list} -x #{ssh_user} --sudo") or raise "Knife bootstrap failed"
99
- rescue
100
- tries -= 1
101
- puts "Cannot connect to node, trying again... #{tries} left."
102
- retry if tries > 0
103
- end
107
+ try_command(20, "#{knife_exec} bootstrap #{instance_ipaddress} -N #{instance_fqdn[0...-1]} -E #{chef_environment} -i #{chef_identity_file} -r #{chef_run_list} -x #{ssh_user} --sudo") or abort "Knife bootstrap failed"
104
108
  end
105
109
 
106
110
  def get_db_dump_from_s3(instance_ip, s3_bucket_name, dump_tmp_path, ssh_user, dump_file_name)
@@ -128,15 +132,7 @@ class Mondupe
128
132
  db_connect_string = "mongo #{mongo_db_name}"
129
133
  db_connect_string << " -u \"#{mongo_user}\" -p \"#{mongo_pass}\"" if !mongo_user.nil? && !mongo_pass.nil?
130
134
  db_connect_string << " --authenticationDatabase \"#{mongo_auth_db}\"" if !mongo_auth_db.nil?
131
- tries = 20
132
- begin
133
- `#{ssh_command} "echo 'db.serverStatus()' | #{db_connect_string}"` or raise "Connection failed..."
134
- sleep 20
135
- rescue
136
- tries -= 1
137
- puts "Could not connect to DB. Trying again... #{tries} left."
138
- retry if tries > 0
139
- end
135
+ try_command(20, "#{ssh_command} \"echo 'db.serverStatus()' | #{db_connect_string}\"") or abort "Failed to connect"
140
136
  puts "#{Time.now.to_s} - Dropping existing database"
141
137
  `#{ssh_command} "#{db_connect_string} --eval 'db.dropDatabase()'"`
142
138
  if $?.success? then puts "#{Time.now.to_s} - Database drop complete" else abort("Error dropping database") end
@@ -162,7 +158,7 @@ class Mondupe
162
158
  #puts "Connect String: #{db_connect_string}"
163
159
  puts "#{Time.now.to_s} - Running command on #{instance_dns} against #{mongo_db_name}"
164
160
  puts "JS Query: #{java_command}"
165
- db_output = `ssh -i #{ssh_key} #{ssh_user}@#{instance_dns} "#{db_connect_string} --eval '#{java_command}'"`
161
+ db_output = try_command(20, "ssh -i #{ssh_key} #{ssh_user}@#{instance_dns} \"#{db_connect_string} --eval '#{java_command}'\"") or abort "Failed to run command"
166
162
  puts db_output
167
163
  if $?.success? then puts "#{Time.now.to_s} - Command execution complete" else abort("Error executing command") end
168
164
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mondupe
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.34
4
+ version: 0.0.35
5
5
  platform: ruby
6
6
  authors:
7
7
  - Philip Hutchins