ey_cloud_server 1.4.47 → 1.4.49

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,7 +0,0 @@
1
- #!/usr/bin/env bash
2
-
3
- for f in /db/mysql/master-bin*;
4
- do
5
- ionice -c3 rm -f $f;
6
- sleep 30;
7
- done
@@ -1,5 +0,0 @@
1
- #!/usr/bin/env ruby
2
-
3
- require File.dirname(__FILE__) + '/../lib/ey-flex'
4
-
5
- puts EY::BigBrother.check
@@ -1,6 +0,0 @@
1
- #!/usr/bin/env ruby
2
-
3
- $:.unshift File.dirname(__FILE__) + '/../lib'
4
- require 'ey_cloud_server'
5
-
6
- EY::CloudServer::MysqlStart.run(ARGV)
@@ -1,80 +0,0 @@
1
- module EY
2
- class BigBrother
3
- def self.check(chef_dna = '/etc/chef/dna.json')
4
- json = JSON.parse(File.read(chef_dna))
5
-
6
- # {'skip':[
7
- # 'mysqld'
8
- # ],
9
- # 'check':[
10
- # 'ttsrv'
11
- # ]}
12
-
13
- skips = JSON.parse(File.read('/etc/ey-alerts.json')) rescue {}
14
-
15
- new(json.merge(skips)).check
16
- end
17
-
18
- def initialize(dna)
19
- @dna = dna
20
- @result = {}
21
- end
22
-
23
- def nginx_or_apache
24
- server = ''
25
- @dna['applications'].each do |name, app_data|
26
- if app_data['recipes'].detect { |r| r == 'nginx' }
27
- server = 'nginx'
28
- end
29
-
30
- if app_data['recipes'].detect { |r| r == 'passenger' }
31
- server = 'apache2'
32
- end
33
- end
34
- server
35
- end
36
-
37
- def skip?(name)
38
- (@dna['skip']||[]).include?(name)
39
- end
40
-
41
- def check
42
- case @dna['instance_role']
43
- when 'solo'
44
- check_process(nginx_or_apache) unless skip?(nginx_or_apache)
45
- check_mysql unless skip?('mysqld')
46
- when 'app', 'app_master'
47
- check_process(nginx_or_apache) unless skip?(nginx_or_apache)
48
- check_process('haproxy') unless skip?('haproxy')
49
- when 'db_master', 'db_slave'
50
- check_mysql unless skip?('mysqld')
51
- when 'util'
52
- end
53
- (@dna['check']||[]).each do |check|
54
- check_process(check)
55
- end
56
- @result.to_json
57
- end
58
-
59
- def check_mysql
60
- check_process('mysqld')
61
- DBI.connect("DBI:Mysql:mysql:#{@dna['db_host']}", 'root', @dna['users'].first['password'])
62
- rescue DBI::DatabaseError => e
63
- @result['mysqld'] = 'down'
64
- end
65
-
66
- def check_process(name)
67
- return if name == ''
68
- pids = `pgrep #{name}`.split("\n")
69
- if pids.empty?
70
- @result[name] = 'down'
71
- else
72
- if pids.detect {|p| `kill -0 #{p}; echo $?`.chomp.to_i != 0}
73
- @result[name] = 'down'
74
- else
75
- @result[name] = 'up'
76
- end
77
- end
78
- end
79
- end
80
- end
@@ -1,155 +0,0 @@
1
- module EY
2
- module CloudServer
3
- class MysqlStart
4
- def self.run(argv = ARGV, options = {})
5
- options = parse(argv, options)
6
- new(options).run
7
- end
8
-
9
- attr_accessor :password, :check, :start_timeout, :stop_timeout
10
-
11
- def initialize(options = {})
12
- @password = options[:password] || abort("ERROR: You must provide a password.")
13
- @check = options[:check] || abort("ERROR: You must a check interval.")
14
- @start_timeout = options[:start_timeout] || abort("ERROR: You must provide a start timeout.")
15
- @stop_timeout = options[:stop_timeout] || 1200
16
-
17
- abort("ERROR: You must be root.") unless Process.euid == 0
18
- end
19
-
20
- def run
21
- count = 0
22
- if system('/etc/init.d/mysql restart')
23
- mysql_started()
24
- else
25
- log_mysql_event("MySQL did not start within the startup timeout")
26
- loop {
27
- # test to make sure mysql is running
28
- if mysql_running()
29
- log_mysql_event("MySQL did start and is working through crash recovery")
30
- slept = 0
31
- loop {
32
- if system("mysqladmin -p#{password} status") # mysql is accessible
33
- log_mysql_event("MySQL completed crash recovery, performing clean restart")
34
- system('killall -TERM mysqld') # safe shutdown of mysql
35
- termslept = 0
36
- termlimit = stop_timeout
37
- loop {
38
- break if not mysql_running()
39
- sleep(check)
40
- termslept = termslept + check
41
- if termslept > termlimit
42
- log_mysql_event("MySQL did not shut down cleanly within the time limit, killing")
43
- system('killall -9 mysqld')
44
- end
45
- }
46
- system('/etc/init.d/mysql zap') # clear files
47
- if system('/etc/init.d/mysql restart') # clean start
48
- mysql_started()
49
- end
50
- else
51
- log_mysql_event("MySQL has been starting for #{slept/60} minutes and is still attempting to start") if slept % 120 == 0
52
- sleep(check)
53
- end
54
- break if not mysql_running()
55
- slept = slept + check
56
- if slept > start_timeout
57
- log_mysql_event("MySQL was not able to start after #{slept/60} minutes and was forcibly killed")
58
- system("killall -9 mysqld")
59
- end
60
- }
61
- else
62
- log_mysql_event("MySQL did not start, zapping")
63
- begin
64
- pidfile = '/var/run/mysqld/mysqld.pid'
65
- if File.exists?(pidfile)
66
- File.open('/var/run/mysqld/mysqld.pid', 'r') do |f|
67
- pid = f.read.to_i
68
- Process.kill("TERM", pid)
69
-
70
- mysqld_is_dead = false
71
- started_at = Time.now
72
- # /etc/init.d/mysql has 120 as STOPTIMEOUT, so we should
73
- # wait at least that long
74
- until mysqld_is_dead || ((Time.now - started_at) > 120)
75
- begin
76
- Process.kill(0, pid)
77
- sleep 1
78
- rescue Errno::ESRCH # no such process
79
- mysqld_is_dead = true
80
- end
81
- end
82
- end
83
- end
84
- rescue Exception => e
85
- File.open('/root/chef-mysql.log', 'a') do |f|
86
- f.write("Blew up: \n")
87
- f.write(e.message)
88
- f.write("\n")
89
- f.write(e.backtrace.join("\t\n"))
90
- end
91
- end
92
- system('/etc/init.d/mysql zap')
93
- if system('/etc/init.d/mysql restart')
94
- mysql_started()
95
- end
96
- end
97
- count += 1
98
- if count > 10
99
- log_mysql_event("Failed to start mysql after 10 attempts, raising error.")
100
- exit(1)
101
- end
102
- sleep 1
103
- }
104
- end
105
- end
106
-
107
- def log_mysql_event(message)
108
- `echo #{message} >> /root/chef-mysql.log`
109
- end
110
-
111
- def mysql_started()
112
- log_mysql_event("MySQL restarted successfully")
113
- exit 0
114
- end
115
-
116
- def mysql_running()
117
- system("ps -u mysql | grep '[m]ysqld'")
118
- end
119
-
120
- def self.parse(argv, options = {})
121
- opts = OptionParser.new do |opts|
122
- opts.version = VERSION
123
-
124
- opts.banner = "Usage: mysql_start [-flag]"
125
- opts.define_head "mysql_start: start, recover, zap, or otherwise pound mysql into submission."
126
- opts.separator '*'*80
127
-
128
- opts.on("-p", "--password PASSWORD", "Root password for mysqladmin.") do |password|
129
- options[:password] = password
130
- end
131
-
132
- opts.on("-c", "--check NUMBER", "Check mysql interval in seconds.") do |check|
133
- options[:check] = check.to_i
134
- end
135
-
136
- opts.on("-t", "--timeout NUMBER", "Maximum wait time in seconds. (DEPRECATED)") do |start_timeout|
137
- options[:start_timeout] = start_timeout.to_i
138
- end
139
-
140
- opts.on("-a", "--start NUMBER", "Startup timeout in seconds.") do |start_timeout|
141
- options[:start_timeout] = start_timeout.to_i
142
- end
143
-
144
- opts.on("-o", "--stop NUMBER", "Graceful termination timeout in seconds.") do |stop_timeout|
145
- options[:stop_timeout] = stop_timeout.to_i
146
- end
147
- end
148
-
149
- opts.parse!(argv)
150
-
151
- options
152
- end
153
- end
154
- end
155
- end
@@ -1,12 +0,0 @@
1
- require File.dirname(__FILE__) + '/spec_helper'
2
-
3
- describe "BigBrother" do
4
- it "works" do
5
- setup_dna({})
6
-
7
- response = EY::BigBrother.check(tmp_dir + "/dna.json")
8
- response.should == "{}"
9
-
10
- teardown_dna({})
11
- end
12
- end