mondupe 0.0.3 → 0.0.4

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 +3 -2
  3. data/lib/mondupe.rb +8 -11
  4. metadata +1 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 34fd78b237de1808b0864a03c5849ec4502a775e
4
- data.tar.gz: a07ddd4d9f5bc36c9d2495158cb2661c8b460434
3
+ metadata.gz: e7d703857e8d7c12215b8cbb9bb707777fc7c6d7
4
+ data.tar.gz: f1c44d57c2d7d8acc440cd67d2da43efd6214b73
5
5
  SHA512:
6
- metadata.gz: 3ebc59372c5391aa062007d073a8742719077a59a6084094d951fe526b01b90501a25b33e3f119fb2032710d7f108141f3988af7b86a0fe42556e25bc8ad2c4b
7
- data.tar.gz: 455bb2195c14051966791fb1a15effb331ecd10fdab9c55a2a1bbb6fe82058a45d5e3880e02c9da285851ff22ccf2abc6b701a98e4e33ca75b7c6ebf43fdafe4
6
+ metadata.gz: 3a1bd390cece32936cc9dc0f8f5f7305b3933f143ab92184b99928c428d8634910260633155a82fb4fe869d618721402d9322507a0c4a4d5c1865e88a6f59d20
7
+ data.tar.gz: 9008e32d33169ac451c15d97b0b976dc6df9cf015cfa6f138b7b9c0d8262e59f47546a155bf8a77809f58e1d491407af8ba944768452c2ffb6316c50e89d9bd0
data/bin/mondupe CHANGED
@@ -113,6 +113,7 @@ key_pair_name = ENV['MONDUPE_KEY_PAIR_NAME'] || nil
113
113
  security_group = ENV['MONDUPE_SECURITY_GROUP'] || nil
114
114
  s3_bucket_name = ENV['MONDUPE_S3_BUCKET_NAME'] || nil
115
115
  dump_file_name = ENV['MONDUPE_DUMP_FILE_NAME'] || 'mongodb.dump.tgz'
116
+ knife_exec = ENV['MONDUPE_KNIFE_EXEC'] || 'knife'
116
117
  instance_volume_size = 60
117
118
 
118
119
  case ARGV[0]
@@ -122,7 +123,7 @@ when "create"
122
123
  puts "Creating AWS EC2 Instance with MongoDB and restoring from latest production backup"
123
124
  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)
124
125
  Mondupe.new.create_dns(instance_fqdn, route53_domain, instance)
125
- Mondupe.new.bootstrap(instance_name, instance_fqdn, instance.ip_address, chef_environment, chef_identity_file, chef_run_list, ssh_user)
126
+ Mondupe.new.bootstrap(instance_name, instance_fqdn, instance.ip_address, chef_environment, chef_identity_file, chef_run_list, ssh_user, knife_exec)
126
127
  Mondupe.new.get_db_dump_from_s3(instance.ip_address, s3_bucket_name, dump_tmp_path, ssh_user, dump_file_name)
127
128
  Mondupe.new.restore_db(instance.ip_address, dump_tmp_path, ssh_key, ssh_user, dump_file_name)
128
129
  puts " - - - Total Run Time: #{((total_seconds % 3600) / 60).to_i}m #{((total_seconds % 3600) % 60).to_i}s - - -"
@@ -131,7 +132,7 @@ when "delete"
131
132
  when "bootstrap"
132
133
  puts "bootstrapping node"
133
134
  # Find the instance and create the instance object here
134
- Mondupe.new.bootstrap(instance_name, instance_fqdn, instance_ipaddress, chef_environment, chef_identity_file, chef_run_list, ssh_user)
135
+ Mondupe.new.bootstrap(instance_name, instance_fqdn, instance_ipaddress, chef_environment, chef_identity_file, chef_run_list, ssh_user, knife_exec)
135
136
  when "dumps3"
136
137
  puts "getting dump"
137
138
  Mondupe.new.get_db_dump_from_s3(instance_ipaddress, s3_bucket_name, dump_tmp_path, ssh_user, dump_file_name)
data/lib/mondupe.rb CHANGED
@@ -4,12 +4,9 @@ require 'aws-sdk'
4
4
 
5
5
  class Mondupe
6
6
  def create_instance(instance_name, instance_image_id, instance_type, instance_count, security_group, key_pair_name, expire_days, instance_owner, instance_volume_size)
7
- AWS.config(:access_key_id => ENV['AWS_ACCESS_KEY_ID'], :secret_access_key => ENV['AWS_SECRET_ACCESS_KEY'], region: 'us-east-1')
7
+ #AWS.config(:access_key_id => ENV['AWS_ACCESS_KEY_ID'], :secret_access_key => ENV['AWS_SECRET_ACCESS_KEY'], region: 'us-east-1')
8
8
 
9
9
  ec2 = AWS::EC2.new(:access_key_id => ENV['AWS_ACCESS_KEY_ID'], :secret_access_key => ENV['AWS_SECRET_ACCESS_KEY'])
10
-
11
- puts "Creating with - Security Group: #{security_group} Instance Owner: #{instance_owner}"
12
-
13
10
  key_pair = ec2.key_pairs[key_pair_name]
14
11
 
15
12
  # Use this to create a new security group - Can have preset options
@@ -27,7 +24,7 @@ class Mondupe
27
24
  }],
28
25
  :instance_type => instance_type,
29
26
  :count => instance_count,
30
- :security_groups => security_group,
27
+ :security_groups => [ security_group ],
31
28
  :key_pair => key_pair
32
29
  )
33
30
 
@@ -90,13 +87,13 @@ class Mondupe
90
87
  end
91
88
 
92
89
 
93
- def bootstrap(instance_name, instance_fqdn, instance_ipaddress, chef_environment, chef_identity_file, chef_run_list, ssh_user)
90
+ def bootstrap(instance_name, instance_fqdn, instance_ipaddress, chef_environment, chef_identity_file, chef_run_list, ssh_user, knife_exec)
94
91
  # Bootstrap the new instance with chef
95
92
  puts "Bootstraping node with Chef..."
96
93
  puts "Running..."
97
- puts "knife bootstrap #{instance_ipaddress} -N #{instance_fqdn[0...-1]} -E #{chef_environment} -i #{chef_identity_file} -r #{chef_run_list} -x #{ssh_user} --sudo"
94
+ #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"
98
95
  sleep 30
99
- system("knife bootstrap #{instance_ipaddress} -N #{instance_fqdn[0...-1]} -E #{chef_environment} -i #{chef_identity_file} -r #{chef_run_list} -x #{ssh_user} --sudo")
96
+ 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")
100
97
  end
101
98
 
102
99
  def get_db_dump_from_s3(instance_ip, s3_bucket_name, dump_tmp_path, ssh_user, dump_file_name)
@@ -117,11 +114,11 @@ class Mondupe
117
114
  # TODO - Fail the process if any step fails
118
115
  puts "#{Time.now.to_s} - Dropping existing database"
119
116
  `ssh -i #{ssh_key} #{ssh_user}@#{instance_ip} "echo 'db.dropDatabase()' | mongo cde_production"`
120
- puts "#{Time.now.to_s} - Database drop complete"
117
+ if $?.success? then puts "#{Time.now.to_s} - Database drop complete" else die("Error dropping database") end
121
118
  puts "Restoring Mongo Database from extracted dump: #{File.join(dump_tmp_path, "cde_production")}"
122
- `ssh -i #{ssh_key} #{ssh_user}@#{instance_ip} "cd /tmp; tar xf #{dump_file_name}; time mongorestore /tmp/cde_production"`
119
+ `ssh -i #{ssh_key} #{ssh_user}@#{instance_ip} "cd #{dump_tmp_path}; tar xf #{dump_file_name}; time mongorestore /tmp/cde_production"`
123
120
  puts "Removing database archive file"
124
- `ssh -i #{ssh_key} #{ssh_user}@#{instance_ip} "rm -rf /tmp/#{File.join(dump_tmp_path, dump_file_name)}"`
121
+ `ssh -i #{ssh_key} #{ssh_user}@#{instance_ip} "rm -rf #{File.join(dump_tmp_path, dump_file_name)}"`
125
122
  puts "#{Time.now.to_s} - Removing saved searches"
126
123
  `ssh -i #{ssh_key} #{ssh_user}@#{instance_ip} "mongo cde_production --eval \\"db.users.update({save_searches: {$ne: null}}, {$unset: {save_searches: ''}}, {multi: true})\\""`
127
124
  puts "#{Time.now.to_s} - Cleaning up our mess..."
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.3
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Philip Hutchins