sr-scripts 0.1.10 → 0.1.11

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.
data/bin/sr-detect-slaves CHANGED
@@ -56,19 +56,35 @@ def print_all_slaves (server, all_servers, padding)
56
56
  slave_servers = all_servers.find_all { |s| s.tags["master_instance_id"] == server.id }
57
57
  slave_servers.each do |slave|
58
58
  padding += 6
59
- print_server(slave, padding)
60
-
61
- print_all_slaves(slave, all_servers, padding) unless slave.tags["master_status"] == "master"
59
+ unless slave.tags["master_status"] == "master"
60
+ print_server(slave, padding)
61
+ print_all_slaves(slave, all_servers, padding)
62
+ end
62
63
  end
63
64
  end
64
65
 
66
+
65
67
  master_servers = all_servers.find_all { |server| server.tags["master_status"] == "master" }
66
68
  p master_servers.length
67
69
 
70
+ $found_servers = []
71
+
68
72
  master_servers.each do |master|
69
73
  p "FOUND MASTER: #{master.id}"
70
74
  padding = 10
71
75
  print_server(master, padding)
76
+ $found_servers.push master.id
77
+ print_all_slaves(master, all_servers, padding)
78
+ end
79
+
80
+
81
+ master_servers = all_servers.find_all { |server| server.tags["master_status"] == "master-retired" }
82
+ p master_servers.length
83
+
84
+ master_servers.each do |master|
85
+ p "FOUND RETIRED MASTER: #{master.id}"
86
+ padding = 10
87
+ print_server(master, padding)
72
88
  print_all_slaves(master, all_servers, padding)
73
89
  end
74
90
 
data/bin/sr-log-monitor CHANGED
@@ -14,7 +14,8 @@ file_changes = false
14
14
  files.each do |file|
15
15
  p "File Not Found: #{file}" && break unless File.exists?(file)
16
16
  last_position = positions[file] || 0
17
- if last_position != File.size?(file)
17
+ file_size = File.size?(file) || 0
18
+ if last_position != file_size
18
19
  f = File.open(file, 'rb')
19
20
  f.seek last_position
20
21
  puts "#### #{file} #####"
@@ -22,7 +23,7 @@ files.each do |file|
22
23
  puts "#### #{file} END ####"
23
24
  file_changes = true
24
25
  end
25
- positions[file] = File.size?(file)
26
+ positions[file] = file_size
26
27
  end
27
28
 
28
29
  File.open(position_file, 'w') do |f|
@@ -7,6 +7,7 @@ require 'optparse'
7
7
  require 'sr-scripts'
8
8
 
9
9
  options = {}
10
+ options[:skip_master] = false
10
11
 
11
12
  optparse = OptionParser.new do|opts|
12
13
  opts.on( '--current-master-id INSTANCE_ID', 'AWS Instance Id Of Current Master Machine') do |o|
@@ -21,6 +22,9 @@ optparse = OptionParser.new do|opts|
21
22
  opts.on( '--mysql-pass PASSWORD', 'Mysql Password') do |o|
22
23
  options[:mysql_password] = o
23
24
  end
25
+ opts.on( '--skip-master', 'Use This Flag To Skip Connecting To --current-master-id') do |o|
26
+ options[:skip_master] = true
27
+ end
24
28
  opts.on( '-h', '--help', 'Display this screen' ) do
25
29
  puts opts
26
30
  exit
@@ -30,7 +34,7 @@ end
30
34
  optparse.parse!
31
35
 
32
36
  if(options[:current_master_id] == nil || options[:new_master_id] == nil)
33
- p "Must specify --current-master-id AND --new-master-id"
37
+ puts "Must specify --current-master-id, --new-master-id, --mysql-user, --mysql-pass"
34
38
  exit
35
39
  end
36
40
 
@@ -40,31 +44,51 @@ def kill_mysql_connections(db)
40
44
  results = db.query "SHOW PROCESSLIST"
41
45
  results.each_hash do |row|
42
46
  unless row["User"] == "system user" || row["Command"] == 'Binlog Dump' || row["Info"] == "SHOW PROCESSLIST"
43
- puts row["Id"]
44
- db.query "KILL #{row['Id']};"
47
+ puts "KILLING QUERY ID: #{row["Id"]}"
48
+ begin
49
+ db.query "KILL #{row['Id']};"
50
+ rescue
51
+ puts "INFO: COULDN'T KILL CONNECTION ID #{row['Id']}"
52
+ end
45
53
  end
46
54
  end
47
55
  end
48
56
 
49
- def get_private_ip(fog, instance_id)
50
- return fog.servers.get(instance_id).private_ip_address
57
+ def get_public_ip(fog, instance_id)
58
+ return fog.servers.get(instance_id).public_ip_address
51
59
  end
52
60
 
53
61
  mysql_user = options[:mysql_user]
54
62
  mysql_pass = options[:mysql_password]
55
63
 
56
- current_master_ip = get_private_ip(connection, options[:current_master_id])
57
- new_master_ip = get_private_ip(connection, options[:new_master_id])
64
+ current_master_ip = get_public_ip(connection, options[:current_master_id])
65
+ new_master_ip = get_public_ip(connection, options[:new_master_id])
58
66
 
59
- current_master = Mysql.new(current_master_ip, mysql_user, mysql_pass)
60
- new_master = Mysql.new(new_master_ip, mysql_user, mysql_pass)
61
-
62
- current_master.query("SET GLOBAL read_only = 1")
63
- sleep 1 # HACKY CRAP
64
- kill_mysql_connections current_master
65
- new_master.query("STOP SLAVE;")
66
- new_master.query("SET GLOBAL read_only = 0")
67
+ current_master, new_master = nil
67
68
 
69
+ unless options[:skip_master]
70
+ begin
71
+ current_master = Mysql.new(current_master_ip, mysql_user, mysql_pass)
72
+ p current_master.query("SELECT version();")
73
+ rescue
74
+ puts "Error Connecting to --master-instance-id. Try running with --skip-master"
75
+ exit 1
76
+ end
77
+ end
68
78
 
79
+ begin
80
+ new_master = Mysql.new(new_master_ip, mysql_user, mysql_pass)
81
+ rescue
82
+ puts "Error connecting to new master"
83
+ exit 1
84
+ end
69
85
 
86
+ unless options[:skip_master]
87
+ current_master.query("SET GLOBAL read_only = 1")
88
+ sleep 1 # HACKY CRAP
89
+ kill_mysql_connections current_master
90
+ end
91
+ new_master.query("STOP SLAVE;")
92
+ new_master.query("SET GLOBAL read_only = 0")
70
93
 
94
+ puts "Script Complete"
@@ -1,5 +1,5 @@
1
1
  module Sr
2
2
  module Scripts
3
- VERSION = "0.1.10"
3
+ VERSION = "0.1.11"
4
4
  end
5
5
  end
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 1
8
- - 10
9
- version: 0.1.10
8
+ - 11
9
+ version: 0.1.11
10
10
  platform: ruby
11
11
  authors:
12
12
  - Davy Campano
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2012-03-21 00:00:00 -04:00
17
+ date: 2012-03-22 00:00:00 -04:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency