dango 0.4.8 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -3,13 +3,14 @@
3
3
  # sessionとsidの管理(1セッションごとにインスタンス化される)
4
4
  class SessionManager
5
5
  MaxSidCounter = 999999
6
-
6
+
7
+ # initialize
7
8
  def initialize(shared, rails_env)
8
9
  @shared = shared
9
10
  @rails_env = rails_env
10
11
 
11
12
  @session_list = {}
12
- @session_mutex = Mutex.new
13
+ @session_mutex = DangoMutex.new(:session_mutex)
13
14
 
14
15
  @shared[:_session_manager] = {}
15
16
  end
@@ -17,26 +18,30 @@ class SessionManager
17
18
 
18
19
  # session開始
19
20
  def start_session()
20
- @session_mutex.synchronize do
21
+ sid = nil
22
+ @session_mutex.timeout_sync(3, :start_session) do
21
23
  sid = generate_sid()
22
- @session_list[Thread.current.object_id] = {:sid => sid}
23
24
  end
25
+ @session_list[Thread.current.object_id] = {:sid => sid}
24
26
  end
25
27
 
26
28
  # session終了
27
29
  def close_session(sid)
28
- @session_mutex.synchronize do
30
+ @session_mutex.timeout_sync(3, :close_session) do
29
31
  drop_sid()
30
- # @session_list[Thread.current.object_id] = nil
31
- @session_list.delete(Thread.current.object_id)
32
32
  end
33
+ # @session_list[Thread.current.object_id] = nil
34
+ @session_list.delete(Thread.current.object_id)
33
35
  end
34
36
 
35
37
  # sessionへのアクセス
36
38
  def session
37
- @session_mutex.synchronize do
38
- @session_list[Thread.current.object_id]
39
- end
39
+ @session_list[Thread.current.object_id]
40
+ end
41
+
42
+ # session_listへのアクセス
43
+ def session_list
44
+ @session_list
40
45
  end
41
46
 
42
47
 
@@ -12,7 +12,7 @@ module DangoFrameworkModule
12
12
  @config = config
13
13
  @data = {}
14
14
  @mutex = {}
15
- # @mutex = Mutex.new
15
+ # @mutex = DangoMutex.new(:shared_mutex)
16
16
 
17
17
  @transact_key = {}
18
18
  @transact_thread = {}
@@ -42,8 +42,8 @@ module DangoFrameworkModule
42
42
  raise(DangoFrameworkException, "Shared key is not exist.")
43
43
  end
44
44
 
45
- # @mutex[key].synchronize do
46
- @mutex.synchronize do
45
+ # @mutex[key].timeout_sync(3, "transaction_old #{key}") do
46
+ @mutex.timeout_sync(3, "transaction_old") do
47
47
  # data = yield(@data[key].deep_dup)
48
48
  data = yield(@data[key])
49
49
  @data[key] = data.deep_dup
@@ -66,8 +66,8 @@ module DangoFrameworkModule
66
66
  raise(DangoFrameworkException, "Shared key is not exist.")
67
67
  end
68
68
 
69
- @mutex[key].synchronize do
70
- # @mutex.synchronize do
69
+ @mutex[key].timeout_sync(3, "transaction #{key}") do
70
+ # @mutex.timeout_sync(3, "transaction") do
71
71
  @transact_key[Thread.current] = key # 違うスレッドからcommitできないように
72
72
 
73
73
  raise("nested transaction #{key}") if @transact_thread.has_key?(key)
@@ -148,8 +148,8 @@ module DangoFrameworkModule
148
148
  # raise(DangoFrameworkException, "Shared key is not exist.")
149
149
  end
150
150
 
151
- @mutex[key].synchronize do
152
- # @mutex.synchronize do
151
+ @mutex[key].timeout_sync(3, "[] #{key}") do
152
+ # @mutex.timeout_sync(3, "[]") do
153
153
  @data[key].deep_dup
154
154
  end
155
155
  end
@@ -165,12 +165,12 @@ module DangoFrameworkModule
165
165
 
166
166
  # 未定義なら定義する
167
167
  if !@data.has_key?(key)
168
- @mutex[key] = Mutex.new
168
+ @mutex[key] = DangoMutex.new("shared_mutex_#{key}")
169
169
  end
170
170
 
171
171
  # ロックしてデータを入れる
172
- @mutex[key].synchronize do
173
- # @mutex.synchronize do
172
+ @mutex[key].timeout_sync(3, "[]= #{key}") do
173
+ # @mutex.timeout_sync(3, "[]=") do
174
174
  @data[key] = value.deep_dup
175
175
  end
176
176
 
@@ -4,23 +4,23 @@
4
4
  class SocketList
5
5
  def initialize
6
6
  @sl_hash = Hash.new
7
- @sl_mutex = Mutex.new
7
+ @sl_mutex = DangoMutex.new(:socket_list_mutex)
8
8
  end
9
9
 
10
10
  def all_sid()
11
- @sl_mutex.synchronize do
11
+ @sl_mutex.timeout_sync(4, :all_sid) do
12
12
  @sl_hash.keys
13
13
  end
14
14
  end
15
15
 
16
16
  def delete(sid)
17
- @sl_mutex.synchronize do
17
+ @sl_mutex.timeout_sync(4, :delete) do
18
18
  @sl_hash.delete(sid)
19
19
  end
20
20
  end
21
21
 
22
22
  def add(sid, sock)
23
- @sl_mutex.synchronize do
23
+ @sl_mutex.timeout_sync(4, :add) do
24
24
  raise("already exist sid(#{sid.inspect})") if @sl_hash.has_key?(sid)
25
25
  raise("sock(#{sock.inspect}) is not Socket") if sock.kind_of?(Socket)
26
26
  @sl_hash[sid] = sock
@@ -28,7 +28,7 @@ class SocketList
28
28
  end
29
29
 
30
30
  def [](sid)
31
- @sl_mutex.synchronize do
31
+ @sl_mutex.timeout_sync(4, "[]") do
32
32
  # raise("not exist sid(#{sid.inspect})") if ! @sl_hash.has_key?(sid)
33
33
  return(nil) if ! @sl_hash.has_key?(sid)
34
34
  @sl_hash[sid]
@@ -3,251 +3,464 @@ ENV['RAILS_ENV'] = ENV['RAILS_ENV'] || 'development'
3
3
 
4
4
  require "pp"
5
5
  require "timeout"
6
+ require "yaml"
7
+ require "find"
6
8
 
7
9
 
8
- # verboseモードのフラグを立てる処理
9
- def check_verbose_mode()
10
- $is_verbose = (ENV["verbose"] == "true" || ENV["verbose"] == "on") ? true : false
11
- end
10
+ require "dango/framework_base"
11
+
12
+ class DangoRakeUtil
13
+ CheckConnectLogFile = "log/check_dango_connect.log" # テスト接続のログ
12
14
 
13
- # pid保存ファイルの読み出し
14
- def get_dango_pid()
15
- begin
16
- pid = open("tmp/pids/dango.#{ENV['RAILS_ENV']}.pid", "rb"){|fh| fh.read }.to_i
17
- rescue
18
- pid = nil
15
+ include DangoUtilModule
16
+
17
+ def initialize
18
+ @log = ""
19
19
  end
20
- puts "pid=#{pid.inspect}" if $is_verbose
21
- pid
22
- end
20
+ attr_accessor(:log)
23
21
 
24
- # pidのプロセスがあるかどうかのチェック
25
- def check_exist_dango_process(pid)
26
- puts "check_exist_dango_process(pid=#{pid})" if $is_verbose
27
-
28
- # そのpidのプロセスがあるかのチェック
29
- is_pid_exist = nil
30
-
31
- if RUBY_PLATFORM == 'i386-mswin32'
32
- # WbemからProcessIDを取得
33
- require "win32ole"
22
+ # verboseモードのフラグを立てる処理
23
+ def check_verbose_mode()
24
+ $is_verbose = (ENV["verbose"] == "true" || ENV["verbose"] == "on") ? true : false
25
+ end
26
+
27
+ # 出力+ログ
28
+ def puts_noverbose(str)
29
+ @log += "#{Time.now_to_s} #{str.to_s}\n"
30
+ puts str.to_s
31
+ end
32
+
33
+ # 出力+ログ(verbose)
34
+ def puts_verbose(str)
35
+ @log += "#{Time.now_to_s} #{str.to_s}\n"
36
+ puts str.to_s if $is_verbose
37
+ end
38
+
39
+ # pid保存ファイルの読み出し
40
+ def get_dango_pid()
34
41
  begin
35
- n_locator = WIN32OLE.new("WbemScripting.SWbemLocator.1")
36
- n_service = n_locator.ConnectServer
42
+ pid = open("tmp/pids/dango.#{ENV['RAILS_ENV']}.pid", "rb"){|fh| fh.read }.to_i
37
43
  rescue
38
- puts "failed connect to Wbem:#{$!.inspect}" if $is_verbose
39
- return
44
+ pid = nil
40
45
  end
46
+ puts_verbose "pid=#{pid.inspect}"
47
+ pid
48
+ end
49
+
50
+ # pidのプロセスがあるかどうかのチェック
51
+ def check_exist_dango_process(pid)
52
+ puts_verbose "check_exist_dango_process(pid=#{pid})"
41
53
 
42
- set = n_service.ExecQuery("select Caption, ProcessID from Win32_Process where ProcessID = #{pid}")
43
- set.each do |one|
44
- # puts(sprintf("Win32_Process %8d %s", one.ProcessID, one.Caption))
45
- if one.ProcessID == pid
46
- is_pid_exist = true
54
+ # そのpidのプロセスがあるかのチェック
55
+ is_pid_exist = nil
56
+
57
+ if RUBY_PLATFORM == 'i386-mswin32'
58
+ # WbemからProcessIDを取得
59
+ require "win32ole"
60
+ begin
61
+ n_locator = WIN32OLE.new("WbemScripting.SWbemLocator.1")
62
+ n_service = n_locator.ConnectServer
63
+ rescue
64
+ puts_verbose "failed connect to Wbem:#{$!.inspect}"
65
+ return
66
+ end
67
+
68
+ set = n_service.ExecQuery("select Caption, ProcessID from Win32_Process where ProcessID = #{pid}")
69
+ set.each do |one|
70
+ puts_verbose(sprintf("Win32_Process %8d %s", one.ProcessID, one.Caption))
71
+ if one.ProcessID == pid
72
+ is_pid_exist = true
73
+ end
47
74
  end
75
+
76
+ else ## i386-mswin32以外
77
+ is_pid_exist = FileTest.exist?("/proc/#{pid}")
48
78
  end
49
79
 
50
- else ## i386-mswin32以外
51
- is_pid_exist = FileTest.exist?("/proc/#{pid}")
80
+ if is_pid_exist
81
+ puts_verbose "dango_process is exist."
82
+ else
83
+ puts_verbose "dango_process is not exist."
84
+ end
85
+
86
+ is_pid_exist
52
87
  end
53
-
54
- if is_pid_exist
55
- puts "dango_process is exist." if $is_verbose
56
- else
57
- puts "dango_process is not exist." if $is_verbose
88
+
89
+ # プロセス停止
90
+ def stop_process(pid)
91
+ puts_verbose "stop process (pid=#{pid})"
92
+
93
+ if RUBY_PLATFORM == 'i386-mswin32'
94
+ # WbemからProcessIDを取得
95
+ require "win32ole"
96
+ begin
97
+ n_locator = WIN32OLE.new("WbemScripting.SWbemLocator.1")
98
+ n_service = n_locator.ConnectServer
99
+ rescue
100
+ puts_verbose "failed connect to Wbem:#{$!.inspect}"
101
+ return
102
+ end
103
+
104
+ set = n_service.ExecQuery("select Caption, name, ProcessID from Win32_Process where ProcessID = '#{pid}'")
105
+ set.each do |process|
106
+ puts_verbose "stopping #{process.Caption} #{process.name} #{process.ProcessID}"
107
+ process.Terminate 0
108
+ end
109
+
110
+ else ## i386-mswin32以外
111
+ # system("kill #{pid}")
112
+ ret_kill = Process.kill("TERM", pid) rescue nil
113
+ puts_verbose "kill TERM ret_kill=#{ret_kill.inspect}"
114
+
115
+
116
+ # きちんと落ちたかチェック
117
+ is_kill = false
118
+ 20.times do
119
+ sleep 1
120
+ if !File.exist?("/proc/#{pid}")
121
+ is_kill = true
122
+ break
123
+ end
124
+ end
125
+
126
+ if !is_kill # 落ちていなければ、-9で終了
127
+ # system("kill -9 #{pid}")
128
+ begin
129
+ Process.kill("KILL", pid)
130
+ rescue
131
+ puts_verbose "process pid(#{pid}) is exist. but failed kill -9 #{pid}"
132
+ end
133
+ end
134
+ end
58
135
  end
59
-
60
- is_pid_exist
61
- end
62
136
 
63
- # プロセス停止
64
- def stop_process(pid)
65
- puts "stop process (pid=#{pid})" if $is_verbose
66
-
67
- if RUBY_PLATFORM == 'i386-mswin32'
68
- # WbemからProcessIDを取得
69
- require "win32ole"
137
+ # サーバーへの通信を使ったチェック
138
+ def check_dango_connect()
139
+ require 'dango/tester/dango_tester_client'
140
+
141
+ # コンフィグから check_dango_process_cmd を取得
142
+ config = YAML.load(open("#{RAILS_ROOT}/config/dango/#{ENV['RAILS_ENV']}.yml", "rb"){|fh| fh.read})
143
+
144
+ serv_info = {}
145
+ serv_info["host"] = config['network']['host'] || 'localhost'
146
+ serv_info["port"] = config['network']['port'] || 15000
147
+ serv_info["log_file"] = CheckConnectLogFile
148
+ serv_info["log_level"] = Logger::DEBUG
149
+ serv_info["log_max_size"] = 10000000
150
+ serv_info["log_shift_age"] = 1
151
+
152
+ # pp serv_info
153
+
154
+ sid = nil
155
+
70
156
  begin
71
- n_locator = WIN32OLE.new("WbemScripting.SWbemLocator.1")
72
- n_service = n_locator.ConnectServer
73
- rescue
74
- puts "failed connect to Wbem:#{$!.inspect}" if $is_verbose
75
- return
157
+ tester = DangoTesterClient.new # 開始
158
+ tester1 = nil
159
+ timeout(12) do
160
+ tester1 = tester.new_client("tester1", serv_info) # テスター1
161
+
162
+ 10.times do |i|
163
+ sleep 1
164
+ sid = tester1.sid.deep_dup
165
+ tester1.logger.warn "count=#{i} sid=#{sid}"
166
+ break if sid
167
+ end
168
+ end
169
+ rescue TimeoutError
170
+ sid = nil
171
+ ret_kill "DangoTesterClient.TimeoutError" if $is_verbose
172
+ ensure
173
+ tester1.dango_client_close if tester1.respond_to?(:dango_client_close)
174
+ tester1 = nil
175
+ tester.gc_thread_stop
76
176
  end
77
177
 
78
- set = n_service.ExecQuery("select Caption, name, ProcessID from Win32_Process where ProcessID = '#{pid}'")
79
- set.each do |process|
80
- puts "stopping #{process.Caption} #{process.name} #{process.ProcessID}" if $is_verbose
81
- process.Terminate 0
178
+ puts_verbose "sid=#{sid.inspect}"
179
+
180
+ if sid
181
+ is_alive_server = true
182
+ else
183
+ is_alive_server = false
82
184
  end
83
185
 
84
- else ## i386-mswin32以外
85
- # system("kill -9 #{pid}")
86
- system("kill #{pid}")
186
+ is_alive_server
87
187
  end
88
- end
89
188
 
90
- # サーバーへの通信を使ったチェック
91
- def check_dango_connect()
92
- require 'dango/tester/dango_tester_client'
93
-
94
- # コンフィグから check_dango_process_cmd を取得
95
- config = YAML.load(open("config/dango/#{ENV['RAILS_ENV']}.yml", "rb"){|fh| fh.read})
96
-
97
- serv_info = {}
98
- serv_info["host"] = config['network']['host'] || 'localhost'
99
- serv_info["port"] = config['network']['port'] || 15000
100
- serv_info["log_file"] = ""
101
- serv_info["log_level"] = Logger::WARN
102
- serv_info["log_max_size"] = 10000000
103
- serv_info["log_shift_age"] = 10
189
+ # drbからのサーバー呼び出し
190
+ def drb_call(method_name, arg = nil)
191
+ config = YAML.load(open("#{RAILS_ROOT}/config/dango/#{ENV['RAILS_ENV']}.yml", "rb"){|fh| fh.read})
192
+
193
+ raise("backdoor_run_drb_server is false.") if !config['server']['backdoor_run_drb_server']
194
+
195
+ if ENV['url']
196
+ drb_uri = ENV['url']
197
+ else
198
+ drb_uri = config['server']['backdoor_run_drb_url']
199
+ end
200
+ puts_verbose drb_uri
201
+
202
+ ret = nil
203
+ begin
204
+ timeout(3) do
205
+ drb_obj = DRbObject.new_with_uri(drb_uri)
206
+ ret = drb_obj.__send__(method_name.to_s, arg)
207
+ end
208
+ rescue Exception
209
+ raise("DRbError:#{$!.class} #{$!.message} #{$!.backtrace.pretty_inspect}")
210
+ end
211
+ ret
212
+ end
104
213
 
105
- # pp serv_info
106
-
107
- tester = DangoTesterClient.new # 開始
108
-
109
- begin
110
- tester1 = nil
111
- sid = nil
112
- timeout(8) do
113
- tester1 = tester.new_client("tester1", serv_info) # テスター1
214
+ # 落ちた時の情報収集処理
215
+ def get_trouble_status(config, pid = nil)
216
+ # フォルダ作成
217
+ time_str = Time.now.strftime('%Y%m%d_%H%M%S')
218
+ dir_name = "log/#{time_str}_#{ENV['RAILS_ENV']}"
219
+ FileUtils.mkdir(dir_name) rescue nil
220
+
221
+ # サーバーログの保管
222
+ old_file = config['server']['log_file'].to_s
223
+ if File.file?(old_file)
224
+ new_file = "#{dir_name}/#{File.basename(old_file)}"
225
+ puts_verbose "copy #{old_file} #{new_file}"
226
+ FileUtils.copy(old_file, new_file) rescue nil
227
+ end
228
+
229
+ # 接続ログの保管
230
+ if File.file?(CheckConnectLogFile)
231
+ new_file = "#{dir_name}/#{File.basename(CheckConnectLogFile)}"
232
+ puts_verbose "copy #{CheckConnectLogFile} #{new_file}"
233
+ FileUtils.copy(CheckConnectLogFile, new_file) rescue nil
234
+ end
235
+
236
+ # スレッド情報と排他処理情報収集
237
+ begin
238
+ open("#{dir_name}/thread_status.txt", "wb") do |fh|
239
+
240
+ fh.puts "==== log"
241
+ fh.puts log
242
+
243
+ fh.puts "==== get_process_info"
244
+ fh.puts get_process_info(pid)
245
+
246
+ fh.puts "==== get_server_info"
247
+ fh.puts drb_call(:_monitor_get_server_info).pretty_inspect
248
+
249
+ fh.puts "==== thread_list"
250
+ fh.puts drb_call(:_monitor_thread_status).pretty_inspect
251
+
252
+ fh.puts "==== mutex_list"
253
+ fh.puts drb_call(:_monitor_mutex_status).pretty_inspect
254
+
255
+ fh.puts "==== get_socket_list"
256
+ fh.puts drb_call(:_monitor_get_socket_list).pretty_inspect
257
+
258
+ fh.puts "==== get_shared"
259
+ fh.puts drb_call(:_monitor_get_shared).pretty_inspect
260
+
261
+ end
262
+ rescue Exception
263
+ puts_verbose "failed get thread_status."
264
+ end
265
+
266
+ # モード変更
267
+ FileUtils.chmod_R(0777, [dir_name]) rescue nil
268
+
269
+ # ファイルの圧縮
270
+ begin
271
+ require "zip/zip"
272
+ can_zip = true
273
+ rescue LoadError
274
+ can_zip = false
275
+ end
276
+
277
+ if can_zip
278
+ outzipfile = "log/#{time_str}_#{ENV['RAILS_ENV']}.zip"
114
279
 
115
- sleep 3
116
- loop do
117
- sid = tester1.sid
118
- break if sid
119
- sleep 1
280
+ files = []
281
+ Find.find(dir_name) do |filename|
282
+ if FileTest::readable?(filename) and FileTest::file?(filename)
283
+ files.push(filename)
284
+ end
285
+ end
286
+
287
+ Zip::ZipOutputStream.open(outzipfile) do |zos|
288
+ files.each do |name|
289
+ zos.put_next_entry(name)
290
+ File.open(name, "rb"){|f| zos.puts(f.read) }
291
+ end
120
292
  end
293
+
294
+ FileUtils.rm_f(files) rescue nil
295
+ FileUtils.remove_entry(dir_name, true) rescue nil
296
+
297
+ FileUtils.chmod_R(0666, [outzipfile]) rescue nil
121
298
  end
122
- rescue TimeoutError
123
- sid = nil
124
- ensure
125
- tester1.dango_client_close if tester1.respond_to?(:dango_client_close)
126
- tester1 = nil
127
- tester.gc_thread_stop
128
- end
129
-
130
- puts "sid=#{sid.inspect}" if $is_verbose
131
-
132
- if sid
133
- is_alive_server = true
134
- else
135
- is_alive_server = false
299
+
136
300
  end
137
-
138
- is_alive_server
139
301
  end
140
302
 
141
303
 
304
+ ################ rakeコマンドの指定 ##################
305
+
142
306
  namespace :dango do
143
307
  # desc "make swf"
144
308
  # task :make_swf do
145
- # puts "complete make_swf." if $is_verbose
309
+ # dru.puts_noverbose "complete make_swf."
146
310
  # end
147
311
 
148
312
  desc "stop dango process"
149
313
  task :stop_dango_process do
150
- check_verbose_mode() # verboseモードのフラグを立てる処理
314
+ dru = DangoRakeUtil.new
315
+ dru.check_verbose_mode() # verboseモードのフラグを立てる処理
151
316
 
152
- pid = get_dango_pid()
153
- stop_process(pid) if pid # pidがあればプロセス停止
154
- puts "complete stop dango process." if $is_verbose
317
+ pid = dru.get_dango_pid()
318
+ dru.stop_process(pid) if pid # pidがあればプロセス停止
319
+ dru.puts_noverbose "complete stop dango process."
155
320
  end
156
321
 
157
322
  desc "check dango process"
158
323
  task :check_dango_process do
159
- check_verbose_mode() # verboseモードのフラグを立てる処理
324
+ dru = DangoRakeUtil.new
325
+ dru.check_verbose_mode() # verboseモードのフラグを立てる処理
326
+ dru.puts_noverbose "check_dango_process"
160
327
 
161
- pid = get_dango_pid() # pidのチェック
162
- is_pid_exist = check_exist_dango_process(pid) # pidのプロセスがあるかどうかのチェック
163
- is_alive_server = check_dango_connect() if is_pid_exist # サーバーへの通信を使ったチェック
328
+ pid = dru.get_dango_pid() # pidのチェック
329
+ is_pid_exist = dru.check_exist_dango_process(pid) # pidのプロセスがあるかどうかのチェック
330
+ is_alive_server = dru.check_dango_connect() if is_pid_exist # サーバーへの通信を使ったチェック
164
331
 
165
332
  # コンフィグから check_dango_process_cmd を取得
166
- config = YAML.load(open("config/dango/#{ENV['RAILS_ENV']}.yml", "rb"){|fh| fh.read})
333
+ config = YAML.load(open("#{RAILS_ROOT}/config/dango/#{ENV['RAILS_ENV']}.yml", "rb"){|fh| fh.read})
167
334
  check_dango_process_cmd = config['server']['check_dango_process_cmd'] || nil
168
335
 
169
336
  # is_pid_existがないならcheck_dango_process_cmd実行
170
337
  if check_dango_process_cmd && (! is_alive_server)
171
- stop_process(pid) if pid # pidがあればプロセス停止
338
+ if pid # pidがあればプロセス停止
339
+ dru.get_trouble_status(config, pid) # 落ちた時の情報収集処理
340
+
341
+ dru.stop_process(pid)
342
+ end
343
+ end
344
+
345
+ # テスト接続のログがあればそれを削除する
346
+ if File.file?(DangoRakeUtil::CheckConnectLogFile)
347
+ FileUtils.rm_f([DangoRakeUtil::CheckConnectLogFile])
172
348
  end
173
349
 
174
350
  # サーバーが止まっているので起動処理をかける
175
351
  if check_dango_process_cmd && ((! is_pid_exist) || (! is_alive_server))
176
- puts "check_dango_process_cmd=#{check_dango_process_cmd}" if $is_verbose
352
+ dru.puts_verbose "check_dango_process_cmd=#{check_dango_process_cmd}"
353
+
354
+ # tmp/pidsから
355
+ config = YAML.load(open("#{RAILS_ROOT}/config/dango/#{ENV['RAILS_ENV']}.yml", "rb"){|fh| fh.read})
356
+ check_dango_process_cmd = config['server']['check_dango_process_cmd'] || nil
357
+
177
358
  system(check_dango_process_cmd)
178
359
  end
179
360
 
180
- puts "complete check_dango_process." if $is_verbose
361
+ dru.puts_noverbose "complete check_dango_process."
362
+ end
363
+
364
+ desc "get_trouble_status"
365
+ task :get_trouble_status do
366
+ dru = DangoRakeUtil.new
367
+ dru.check_verbose_mode() # verboseモードのフラグを立てる処理
368
+ dru.puts_noverbose "get_trouble_status"
369
+
370
+ config = YAML.load(open("#{RAILS_ROOT}/config/dango/#{ENV['RAILS_ENV']}.yml", "rb"){|fh| fh.read})
371
+ pid = dru.get_dango_pid() # pidのチェック
372
+ dru.get_trouble_status(config, pid) # 落ちた時の情報収集処理
373
+ dru.puts_noverbose "complete get_trouble_status."
181
374
  end
182
375
 
183
376
  namespace :monitor do
184
377
  desc "get server info"
185
378
  task :get_server_info do
186
- check_verbose_mode() # verboseモードのフラグを立てる処理
187
-
188
- puts "server_reload"
189
- require 'dango/monitor/dango_monitor_client.rb'
190
- begin
191
- dm = DangoMonitorClient.new()
192
- pp dm.get_server_info()
193
- dm.dango_client_close
194
- puts "complete get_server_info."
195
- rescue
196
- pp $!.class
197
- pp $!.message
198
- pp $!.backtrace
199
- puts "failed get_server_info."
379
+ dru = DangoRakeUtil.new
380
+ dru.check_verbose_mode() # verboseモードのフラグを立てる処理
381
+ dru.puts_noverbose "get_server_info"
382
+ pp dru.drb_call(:_monitor_get_server_info)
383
+ end
384
+
385
+ desc "thread_status"
386
+ task :thread_status do
387
+ dru = DangoRakeUtil.new
388
+ dru.check_verbose_mode() # verboseモードのフラグを立てる処理
389
+ dru.puts_noverbose "thread_status"
390
+ pp dru.drb_call(:_monitor_thread_status)
391
+ end
392
+
393
+ desc "mutex_status"
394
+ task :mutex_status do
395
+ dru = DangoRakeUtil.new
396
+ dru.check_verbose_mode() # verboseモードのフラグを立てる処理
397
+ dru.puts_noverbose "mutex_status"
398
+ pp dru.drb_call(:_monitor_mutex_status)
399
+ end
400
+
401
+ desc "get_shared"
402
+ task :get_shared do
403
+ dru = DangoRakeUtil.new
404
+ dru.check_verbose_mode() # verboseモードのフラグを立てる処理
405
+ dru.puts_noverbose "get_shared"
406
+ pp dru.drb_call(:_monitor_get_shared)
407
+ end
408
+
409
+ desc "write_shared"
410
+ task :write_shared do
411
+ dru = DangoRakeUtil.new
412
+ dru.check_verbose_mode() # verboseモードのフラグを立てる処理
413
+ dru.puts_noverbose "write_shared"
414
+ key = ENV["KEY"]
415
+ value = ENV["VALUE"]
416
+ if ! key || ! value
417
+ dru.puts_noverbose "please VALUE. ex. rake dango:monitor:write_shared KEY=room VALUE=true"
418
+ exit
200
419
  end
201
-
420
+ pp dru.drb_call(:_monitor_write_shared, {"key"=>key, "value"=>value})
421
+ end
422
+
423
+ desc "get_socket_list"
424
+ task :get_socket_list do
425
+ dru = DangoRakeUtil.new
426
+ dru.check_verbose_mode() # verboseモードのフラグを立てる処理
427
+ dru.puts_noverbose "get_socket_list"
428
+ pp dru.drb_call(:_monitor_get_socket_list)
429
+ end
430
+
431
+ desc "get_session_list"
432
+ task :get_session_list do
433
+ dru = DangoRakeUtil.new
434
+ dru.check_verbose_mode() # verboseモードのフラグを立てる処理
435
+ dru.puts_noverbose "get_session_list"
436
+ pp dru.drb_call(:_monitor_get_session_list)
202
437
  end
203
438
 
204
439
  desc "server_reload" # サーバーのリロード処理
205
440
  task :server_reload do
206
- check_verbose_mode() # verboseモードのフラグを立てる処理
207
-
208
- puts "server_reload"
209
- require 'dango/monitor/dango_monitor_client.rb'
210
- begin
211
- dm = DangoMonitorClient.new()
212
- pp dm.server_reload()
213
- dm.dango_client_close
214
- puts "complete server_reload."
215
- rescue
216
- pp $!.class
217
- pp $!.message
218
- pp $!.backtrace
219
- puts "failed server_reload."
220
- end
441
+ dru = DangoRakeUtil.new
442
+ dru.check_verbose_mode() # verboseモードのフラグを立てる処理
443
+ dru.puts_noverbose "server_reload"
444
+ pp dru.drb_call(:_monitor_server_reload)
221
445
  end
222
446
 
223
447
  desc "send_system_message" # システムメッセージ配信
224
448
  task :send_system_message do
225
- check_verbose_mode() # verboseモードのフラグを立てる処理
449
+ dru = DangoRakeUtil.new
450
+ dru.check_verbose_mode() # verboseモードのフラグを立てる処理
451
+ dru.puts_noverbose "send_system_message"
226
452
 
227
- puts "send_system_message" if $is_verbose
228
453
  message_type = ENV["TYPE"]
229
454
  if ! message_type
230
- puts "please type. ex. rake dango:monitor:send_system_message TYPE=down_1min"
455
+ dru.puts_noverbose "please type. ex. rake dango:monitor:send_system_message TYPE=down_1min"
231
456
  exit
232
457
  end
233
458
 
234
- require "yaml"
235
- require 'dango/monitor/dango_monitor_client.rb'
236
-
237
459
  system_message = YAML.load(open("config/dango/system_message.yml", "rb"){|fh| fh.read})
238
460
  message = system_message[message_type]
239
461
 
240
- begin
241
- dm = DangoMonitorClient.new()
242
- pp dm.send_system_message(message)
243
- dm.dango_client_close
244
- puts "complete send_system_message."
245
- rescue
246
- pp $!.class
247
- pp $!.message
248
- pp $!.backtrace
249
- puts "failed send_system_message."
250
- end
462
+ dru.drb_call(:_monitor_send_system_message, {"message" => message})
463
+ dru.puts_noverbose "complete send_system_message."
251
464
  end
252
465
 
253
466
  end