mondupe 0.0.35 → 0.0.37
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 +2 -4
- data/lib/mondupe.rb +9 -5
- 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: f0c20d04c3f03e2f9de9259d7e546f2cb3632638
|
4
|
+
data.tar.gz: 20a8340501e8455d0a93a2513ca4c84132adc191
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 48cb854703d9c1bd1f1e476b14b7073eae6e311764cee097ce35cb6bb40f935dd5922430e1a243a8d291e73ef8b2cf969402b3ef7030e2b290ae27d208d983a4
|
7
|
+
data.tar.gz: 9ec1fbe544eda59e97b7ff501bb5930bf5665ba2c1f3105b0116ceed5a93becd192b553a8ff293436e255a44f950293a957e9bf5ff2b4c90049bb52f49d8410b
|
data/bin/mondupe
CHANGED
@@ -113,7 +113,6 @@ opt_parser = OptionParser.new do |opt|
|
|
113
113
|
opt.separator " Optional: (have sane defaults)"
|
114
114
|
opt.separator " - MONDUPE_INSTANCE_IMAGE_ID"
|
115
115
|
opt.separator " - MONDUPE_CHEF_RUN_LIST"
|
116
|
-
opt.separator " - MONDUPE_CHEF_IDENTITY_FILE"
|
117
116
|
opt.separator " - MONDUPE_CHEF_ENVIRONMENT"
|
118
117
|
opt.separator " - MONDUPE_SSH_KEY"
|
119
118
|
opt.separator " - MONDUPE_SSH_USER"
|
@@ -142,7 +141,6 @@ instance_count = 1
|
|
142
141
|
chef_run_list = ENV['MONDUPE_CHEF_RUN_LIST'] || ""
|
143
142
|
chef_environment = ENV['MONDUPE_CHEF_ENVIRONMENT'] || "default"
|
144
143
|
ssh_key = ENV['MONDUPE_SSH_KEY'] || "~/.ssh/id_rsa"
|
145
|
-
chef_identity_file = ENV['MONDUPE_CHEF_IDENTITY_FILE'] || ssh_key
|
146
144
|
ssh_user = ENV['MONDUPE_SSH_USER'] || "ubuntu"
|
147
145
|
route53_domain = ENV['MONDUPE_ROUTE53_DOMAIN'] || nil
|
148
146
|
instance_fqdn = ( instance_name + "." + route53_domain ) unless instance_name.nil? || route53_domain.nil?
|
@@ -160,7 +158,7 @@ when "create"
|
|
160
158
|
puts "Creating AWS EC2 Instance with MongoDB and restoring from latest production backup"
|
161
159
|
instance = Mondupe.new.create_instance(instance_name, instance_image_id, instance_type, instance_count, security_group, key_pair_name, expire_days, instance_owner, instance_volume_size)
|
162
160
|
Mondupe.new.create_dns(instance_fqdn, route53_domain, instance)
|
163
|
-
Mondupe.new.bootstrap(instance_name, instance_fqdn, instance.ip_address, chef_environment,
|
161
|
+
Mondupe.new.bootstrap(instance_name, instance_fqdn, instance.ip_address, chef_environment, chef_run_list, ssh_key, ssh_user, knife_exec)
|
164
162
|
Mondupe.new.get_db_dump_from_s3(instance.ip_address, s3_bucket_name, dump_tmp_path, ssh_user, dump_file_name)
|
165
163
|
Mondupe.new.restore_db(instance.ip_address, dump_tmp_path, ssh_key, ssh_user, dump_file_name, mongo_db_name, mongo_user, mongo_pass, mongo_auth_db)
|
166
164
|
puts " - - - Total Run Time: #{((total_seconds % 3600) / 60).to_i}m #{((total_seconds % 3600) % 60).to_i}s - - -"
|
@@ -169,7 +167,7 @@ when "delete"
|
|
169
167
|
when "bootstrap"
|
170
168
|
puts "bootstrapping node"
|
171
169
|
# Find the instance and create the instance object here
|
172
|
-
Mondupe.new.bootstrap(instance_name, instance_fqdn, instance_host_address, chef_environment,
|
170
|
+
Mondupe.new.bootstrap(instance_name, instance_fqdn, instance_host_address, chef_environment, chef_run_list, ssh_key, ssh_user, knife_exec)
|
173
171
|
when "dumps3"
|
174
172
|
puts "getting dump"
|
175
173
|
Mondupe.new.get_db_dump_from_s3(instance_host_address, s3_bucket_name, dump_tmp_path, ssh_user, dump_file_name)
|
data/lib/mondupe.rb
CHANGED
@@ -78,33 +78,37 @@ class Mondupe
|
|
78
78
|
if rrset.exists?
|
79
79
|
# Update if record exists
|
80
80
|
rrset.update
|
81
|
+
puts "Updated CNAME '#{instance_fqdn}' to point to '#{instance.ip_address}'"
|
81
82
|
else
|
82
83
|
# Create new record if does not exist
|
83
84
|
rrset = zone.rrsets[instance_fqdn, 'CNAME']
|
84
85
|
rrset.resource_records = [ { :value => instance.ip_address } ]
|
85
86
|
rrset.update
|
87
|
+
puts "Added CNAME '#{instance_fqdn}' pointing to '#{instance.ip_address}'"
|
86
88
|
end
|
87
89
|
end
|
88
90
|
|
89
|
-
def try_command(tries, command)
|
91
|
+
def try_command(tries, wait, command)
|
90
92
|
begin
|
91
93
|
`#{command}` or raise "Failure"
|
92
94
|
rescue
|
93
95
|
tries -= 1
|
94
96
|
if tries > 0
|
95
97
|
puts "Trying again. #{tries} left."
|
98
|
+
sleep wait
|
96
99
|
retry
|
97
100
|
end
|
98
101
|
puts "Failed after #{tries} retries..."
|
99
102
|
end
|
100
103
|
end
|
101
104
|
|
102
|
-
def bootstrap(instance_name, instance_fqdn,
|
105
|
+
def bootstrap(instance_name, instance_fqdn, instance_ip, chef_environment, chef_run_list, ssh_key, ssh_user, knife_exec)
|
103
106
|
# Bootstrap the new instance with chef
|
104
107
|
puts "Bootstraping node with Chef..."
|
105
108
|
puts "Running..."
|
106
109
|
#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"
|
107
|
-
try_command(20, "
|
110
|
+
try_command(20, 20, "ssh -i #{ssh_key} #{ssh_user}@#{instance_ip} \"date\"")
|
111
|
+
system("#{knife_exec} bootstrap #{instance_ipaddress} -N #{instance_fqdn[0...-1]} -E #{chef_environment} -i #{ssh_key} -r #{chef_run_list} -x #{ssh_user} --sudo") or abort "Knife bootstrap failed"
|
108
112
|
end
|
109
113
|
|
110
114
|
def get_db_dump_from_s3(instance_ip, s3_bucket_name, dump_tmp_path, ssh_user, dump_file_name)
|
@@ -132,7 +136,7 @@ class Mondupe
|
|
132
136
|
db_connect_string = "mongo #{mongo_db_name}"
|
133
137
|
db_connect_string << " -u \"#{mongo_user}\" -p \"#{mongo_pass}\"" if !mongo_user.nil? && !mongo_pass.nil?
|
134
138
|
db_connect_string << " --authenticationDatabase \"#{mongo_auth_db}\"" if !mongo_auth_db.nil?
|
135
|
-
try_command(20, "#{ssh_command} \"echo 'db.serverStatus()' | #{db_connect_string}\"") or abort "Failed to connect"
|
139
|
+
try_command(20, 20, "#{ssh_command} \"echo 'db.serverStatus()' | #{db_connect_string}\"") or abort "Failed to connect"
|
136
140
|
puts "#{Time.now.to_s} - Dropping existing database"
|
137
141
|
`#{ssh_command} "#{db_connect_string} --eval 'db.dropDatabase()'"`
|
138
142
|
if $?.success? then puts "#{Time.now.to_s} - Database drop complete" else abort("Error dropping database") end
|
@@ -158,7 +162,7 @@ class Mondupe
|
|
158
162
|
#puts "Connect String: #{db_connect_string}"
|
159
163
|
puts "#{Time.now.to_s} - Running command on #{instance_dns} against #{mongo_db_name}"
|
160
164
|
puts "JS Query: #{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"
|
165
|
+
db_output = try_command(20, 20, "ssh -i #{ssh_key} #{ssh_user}@#{instance_dns} \"#{db_connect_string} --eval '#{java_command}'\"") or abort "Failed to run command"
|
162
166
|
puts db_output
|
163
167
|
if $?.success? then puts "#{Time.now.to_s} - Command execution complete" else abort("Error executing command") end
|
164
168
|
end
|