sr-scripts 0.0.11 → 0.0.12
Sign up to get free protection for your applications and to get access to all the features.
- data/bin/sr-ec2-consistent-snapshot +1 -1
- data/bin/sr-promote-to-master +69 -0
- data/lib/sr-scripts/version.rb +1 -1
- metadata +6 -4
@@ -136,7 +136,7 @@ end
|
|
136
136
|
|
137
137
|
random_id = rand(36**8).to_s(36)
|
138
138
|
attributes = Hash.new
|
139
|
-
attributes["instance_id"] = `curl http://169.254.169.254/latest/meta-data/instance-id`
|
139
|
+
attributes["instance_id"] = `curl -s http://169.254.169.254/latest/meta-data/instance-id`
|
140
140
|
attributes["snapshots"] = snapshots.join(",")
|
141
141
|
attributes["timestamp"] = Time.now.to_i
|
142
142
|
attributes["master_log_file"] = master_info["MASTER_LOG_FILE"]
|
@@ -0,0 +1,69 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'rubygems'
|
4
|
+
require 'fog'
|
5
|
+
require 'mysql'
|
6
|
+
require 'optparse'
|
7
|
+
|
8
|
+
options = {}
|
9
|
+
|
10
|
+
optparse = OptionParser.new do|opts|
|
11
|
+
opts.on( '--current-master-id INSTANCE_ID', 'AWS Instance Id Of Current Master Machine') do |o|
|
12
|
+
options[:current_master_id] = o
|
13
|
+
end
|
14
|
+
opts.on( '--new-master-id INSTANCE_ID', 'AWS Instance Id Of Machine To Promote To Master') do |o|
|
15
|
+
options[:new_master_id] = o
|
16
|
+
end
|
17
|
+
opts.on( '--mysql-user USER', 'Mysql User') do |o|
|
18
|
+
options[:mysql_user] = o
|
19
|
+
end
|
20
|
+
opts.on( '--mysql-pass PASSWORD', 'Mysql Password') do |o|
|
21
|
+
options[:mysql_password] = o
|
22
|
+
end
|
23
|
+
opts.on( '-h', '--help', 'Display this screen' ) do
|
24
|
+
puts opts
|
25
|
+
exit
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
optparse.parse!
|
30
|
+
|
31
|
+
if(options[:current_master_id] == nil || options[:new_master_id] == nil)
|
32
|
+
p "Must specify --current-master-id AND --new-master-id"
|
33
|
+
exit
|
34
|
+
end
|
35
|
+
|
36
|
+
connection = Fog::Compute.new(:provider => "AWS", :region => "us-west-1")
|
37
|
+
|
38
|
+
def kill_mysql_connections(db)
|
39
|
+
results = db.query "SHOW PROCESSLIST"
|
40
|
+
results.each_hash do |row|
|
41
|
+
unless row["User"] == "system user" || row["Command"] == 'Binlog Dump' || row["Info"] == "SHOW PROCESSLIST"
|
42
|
+
puts row["Id"]
|
43
|
+
db.query "KILL #{row['Id']};"
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
def get_private_ip(fog, instance_id)
|
49
|
+
return fog.servers.get(instance_id).private_ip_address
|
50
|
+
end
|
51
|
+
|
52
|
+
mysql_user = options[:mysql_user]
|
53
|
+
mysql_pass = options[:mysql_password]
|
54
|
+
|
55
|
+
current_master_ip = get_private_ip(connection, options[:current_master_id])
|
56
|
+
new_master_ip = get_private_ip(connection, options[:new_master_id])
|
57
|
+
|
58
|
+
current_master = Mysql.new(current_master_ip, mysql_user, mysql_pass)
|
59
|
+
new_master = Mysql.new(new_master_ip, mysql_user, mysql_pass)
|
60
|
+
|
61
|
+
current_master.query("SET GLOBAL read_only = 1")
|
62
|
+
sleep 1 # HACKY CRAP
|
63
|
+
kill_mysql_connections current_master
|
64
|
+
new_master.query("STOP SLAVE;")
|
65
|
+
new_master.query("SET GLOBAL read_only = 0")
|
66
|
+
|
67
|
+
|
68
|
+
|
69
|
+
|
data/lib/sr-scripts/version.rb
CHANGED
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sr-scripts
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 7
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 0.0.
|
9
|
+
- 12
|
10
|
+
version: 0.0.12
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Davy Campano
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2011-03-
|
18
|
+
date: 2011-03-25 00:00:00 -04:00
|
19
19
|
default_executable:
|
20
20
|
dependencies: []
|
21
21
|
|
@@ -25,6 +25,7 @@ email:
|
|
25
25
|
executables:
|
26
26
|
- sr-backup-mysql
|
27
27
|
- sr-ec2-consistent-snapshot
|
28
|
+
- sr-promote-to-master
|
28
29
|
- sr-send-email
|
29
30
|
- sr-start-slave
|
30
31
|
- sr-update-dns
|
@@ -39,6 +40,7 @@ files:
|
|
39
40
|
- Rakefile
|
40
41
|
- bin/sr-backup-mysql
|
41
42
|
- bin/sr-ec2-consistent-snapshot
|
43
|
+
- bin/sr-promote-to-master
|
42
44
|
- bin/sr-send-email
|
43
45
|
- bin/sr-start-slave
|
44
46
|
- bin/sr-update-dns
|