murakumo 0.2.6 → 0.2.7
Sign up to get free protection for your applications and to get access to all the features.
data/lib/misc/murakumo_const.rb
CHANGED
@@ -12,6 +12,7 @@ module Murakumo
|
|
12
12
|
@name = name
|
13
13
|
@cloud = cloud
|
14
14
|
@logger = logger
|
15
|
+
@options = options
|
15
16
|
|
16
17
|
# 各種変数の設定
|
17
18
|
{
|
@@ -97,7 +98,7 @@ module Murakumo
|
|
97
98
|
|
98
99
|
begin
|
99
100
|
retval = timeout(@timeout) {
|
100
|
-
HealthCheckerContext.new.instance_eval(@script)
|
101
|
+
HealthCheckerContext.new(:name => @name, :logger => @logger, :options => @options).instance_eval(@script)
|
101
102
|
}
|
102
103
|
rescue Timeout::Error
|
103
104
|
retval = false
|
@@ -8,6 +8,12 @@ module Murakumo
|
|
8
8
|
# ヘルスチェックのコンテキスト
|
9
9
|
class HealthCheckerContext
|
10
10
|
|
11
|
+
def initialize(vars = {})
|
12
|
+
vars.each do |name, val|
|
13
|
+
instance_variable_set("@#{name}", val)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
11
17
|
# TCPチェッカー
|
12
18
|
def tcp_check(port, host = '127.0.0.1')
|
13
19
|
s = TCPSocket.new(host, port)
|
@@ -29,35 +35,38 @@ module Murakumo
|
|
29
35
|
end
|
30
36
|
|
31
37
|
# MySQLのドライバがあれば、MySQLチェッカーを定義
|
32
|
-
|
38
|
+
mysql_class = nil
|
33
39
|
|
34
40
|
begin
|
35
41
|
require 'mysql'
|
36
|
-
|
42
|
+
mysql_class = Mysql
|
37
43
|
rescue LoadError
|
38
44
|
begin
|
39
45
|
require 'mysql2'
|
40
|
-
|
46
|
+
mysql_class = Mysql2
|
41
47
|
rescue LoadError
|
42
48
|
end
|
43
49
|
end
|
44
50
|
|
45
|
-
if
|
46
|
-
|
47
|
-
|
48
|
-
|
51
|
+
if mysql_class
|
52
|
+
class_eval <<-EOS
|
53
|
+
def mysql_check(user, passwd = nil, port_sock = 3306, host = '127.0.0.1', db = nil)
|
54
|
+
port = nil
|
55
|
+
sock = nil
|
49
56
|
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
57
|
+
if port_sock.kind_of?(Integer)
|
58
|
+
port = port_sock
|
59
|
+
else
|
60
|
+
sock = port_sock
|
61
|
+
end
|
55
62
|
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
63
|
+
my = #{mysql_class}.new(host, user, passwd, db, port, sock)
|
64
|
+
!!(my.respond_to?(:ping) ? my.ping : my.stat)
|
65
|
+
rescue => e
|
66
|
+
@logger.debug(e.message)
|
67
|
+
false
|
68
|
+
end
|
69
|
+
EOS
|
61
70
|
end
|
62
71
|
|
63
72
|
end # HealthCheckerContext
|
metadata
CHANGED