dango 0.5.0 → 0.5.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -50,8 +50,10 @@ class DangoClientFramework
50
50
 
51
51
  @connection_encode_type = EncodeTypeMarshal
52
52
 
53
- @recv_count = 0 # 受信回数
54
- @send_count = 0 # 送信回数
53
+ @recv_count = 0 # 受信回数
54
+ @send_count = 0 # 送信回数
55
+ @recv_byte = 0 # 受信バイト数
56
+ @send_byte = 0 # 送信バイト数
55
57
 
56
58
  Signal.trap('INT') do # SIGINT を捕捉する。
57
59
  puts "shutdown"
@@ -146,7 +148,7 @@ class DangoClientFramework
146
148
 
147
149
  # メソッド呼び出し
148
150
  notice_name = ret_obj["_notice_name"]
149
- logger.info "calling method=#{notice_name.inspect} #{@sid} "
151
+ logger.info "calling method notice_name=dango_receive_#{notice_name.inspect} #{@sid} "
150
152
  begin
151
153
  __send__("dango_receive_#{notice_name}", ret_obj)
152
154
  rescue
@@ -63,6 +63,7 @@ class DangoLogger
63
63
  @dango_logger.add(data[:sev], data[:msg], data[:prg])
64
64
  rescue Exception
65
65
  puts "dango_logger:#{error_message($!, 'u')}"
66
+ open("dango_logger.log", "ab"){|fh| fh.puts "#{Time.now_to_s}:#{error_message($!, 'u')}"}
66
67
  exit! # ログのトラブルが出た場合は強制終了
67
68
  end
68
69
  end
@@ -44,7 +44,7 @@ class DangoMutex < Mutex
44
44
  end
45
45
  end
46
46
 
47
- error_msg += "DangoFrameworkMutexTimeoutException" +
47
+ error_msg += "DangoFrameworkMutexTimeoutException " +
48
48
  "self=#{self.mutex_name}(#{lock_name})\n" +
49
49
  "locked_mutex=#{locked_msg}\n" +
50
50
  "#{$!.message}\n" +
@@ -53,7 +53,7 @@ class DangoMutex < Mutex
53
53
  raise(DangoFrameworkMutexTimeoutException, error_msg)
54
54
 
55
55
  rescue Exception
56
- puts "#{$!.class} #{$!.message}\n#{$!.backtrace.pretty_inspect}"
56
+ # puts "#{$!.class} #{$!.message}\n#{$!.backtrace.pretty_inspect}"
57
57
 
58
58
  raise
59
59
  end
@@ -23,118 +23,5 @@ module DefaultDangoReceive
23
23
  end
24
24
 
25
25
 
26
-
27
- ################## メンテナンスアクション系 ##################
28
-
29
- public
30
- # メンテナンスコマンド:サーバーからクライアントへのデータ送信
31
- def dango_receive__monitor_get_server_info(ret_obj)
32
- logger.debug "dango_receive__monitor_get_server_info:#{ret_obj.inspect}"
33
- dango_check_monitor_error()
34
-
35
- get_server_info = {
36
- 'server_start_time' => start_time.strftime("%Y-%m-%d %H:%M:%S"),
37
- 'up_time' => Time.now - start_time,
38
-
39
- 'recv_count' => recv_count, # 受信回数
40
- 'send_count' => send_count, # 送信回数
41
- 'recv_fail_count' => recv_fail_count, # 受信失敗回数
42
- 'send_fail_count' => send_fail_count, # 送信失敗回数
43
-
44
- 'log_level' => log_level_str,
45
- 'log_file' => log_file,
46
- 'log_max_size' => log_max_size,
47
- 'log_shift_age' => log_shift_age,
48
- }
49
-
50
- send_obj = {'code'=>0, 'get_server_info'=>get_server_info}
51
- send_notice('return__monitor_get_server_info', session[:sid], send_obj, :type=>2)
52
- end
53
-
54
- # メンテナンスコマンド:サーバーからクライアントへのデータ送信
55
- def dango_receive__monitor_get_shared(ret_obj)
56
- logger.debug "dango_receive__monitor_get_shared:#{ret_obj.inspect}"
57
- dango_check_monitor_error()
58
-
59
- send_obj = {'code'=>0, 'get_shared'=>shared.to_hash}
60
- send_notice('return__monitor_get_shared', session[:sid], send_obj, :type=>2)
61
- end
62
-
63
- # メンテナンスコマンド:サーバーからクライアントへのデータ送信
64
- def dango_receive__monitor_get_session_list(ret_obj)
65
- logger.debug "dango_receive__monitor_get_session_list:#{ret_obj.inspect}"
66
- dango_check_monitor_error()
67
-
68
- send_obj = {'code'=>0, 'get_session_list'=>session_list}
69
- send_notice('return__monitor_get_session_list', session[:sid], send_obj, :type=>2)
70
- end
71
-
72
- # メンテナンスコマンド:サーバーからクライアントへのデータ送信
73
- def dango_receive__monitor_get_socket_list(ret_obj)
74
- logger.debug "dango_receive__monitor_get_socket_list:#{ret_obj.inspect}"
75
- dango_check_monitor_error()
76
-
77
- send_obj = {'code'=>0, 'get_socket_list'=>socket_list.keys}
78
- send_notice('return__monitor_get_socket_list', session[:sid], send_obj, :type=>2)
79
- end
80
-
81
- # メンテナンスコマンド:サーバーデータ再読み込み
82
- def dango_receive__monitor_server_reload(ret_obj)
83
- logger.debug "dango_receive__monitor_server_reload"
84
- dango_check_monitor_error()
85
-
86
- @server_reload = true
87
- logger.debug "@server_reload=#{@server_reload.inspect}"
88
- send_obj = {'code'=>0, 'message'=>'success'}
89
- send_notice('return__monitor_server_reload', session[:sid], send_obj, :type=>2)
90
- end
91
-
92
- # メンテナンスコマンド:接続者全員へメッセージ送信
93
- def dango_receive__monitor_send_system_message(ret_obj)
94
- logger.debug "dango_receive__monitor_send_system_message:#{ret_obj.inspect}"
95
- dango_check_monitor_error()
96
-
97
- # 全員へ_notice_system_messageを通知
98
- socket_list.keys.each do |sid|
99
- next if session[:sid] == sid
100
- send_obj = { "message" => ret_obj["message"] }
101
- send_notice('_notice_system_message', sid, send_obj)
102
- end
103
-
104
- send_obj = {'code'=>0, }
105
- send_notice('return__monitor_send_system_message', session[:sid], send_obj, :type=>2)
106
- end
107
-
108
- private
109
- # メンテナンスコマンド:エラーの場合
110
- def dango_check_monitor_error()
111
- action_name = session[:_action_name]
112
- peerhost = session[:peer_host]
113
- peeraddr = session[:peer_ip_address]
114
-
115
- logger.debug "dango_check_monitor_error:peerhost=#{peerhost.inspect} peeraddr=#{peeraddr.inspect} @backdoor_host=#{@backdoor_host.inspect}"
116
-
117
- match = false
118
- if peerhost == backdoor_host # ホスト名で書いてある時の一致確認
119
- match = true
120
- else
121
- begin # IPアドレスの一致確認
122
- # match = true if IPAddr.new(@backdoor_host).include?(peeraddr)
123
- if IPAddr.new(@backdoor_host).include?(IPAddr.new(peeraddr))
124
- match = true
125
- end
126
- rescue
127
- end
128
- end
129
-
130
- if !match
131
- notice_name = "return_" + action_name
132
- send_obj = {'code'=>1, 'message'=>"error your ip address"}
133
- send_notice(notice_name, session[:sid], send_obj, :type=>2)
134
- raise(DangoFrameworkMonitorSecurityError)
135
- end
136
- end
137
-
138
-
139
26
  end
140
27
 
@@ -165,7 +165,7 @@ module DangoFrameworkModule
165
165
 
166
166
  DefaultEncodeType = EncodeTypeJSON # デフォルトのエンコードのタイプ
167
167
 
168
- ReadTimeoutSec = 10.0 # データ受信のタイムアウト秒数
168
+ ReadTimeoutSec = 4.0 # データ受信のタイムアウト秒数
169
169
 
170
170
 
171
171
  # デバッグ出力用のメソッド
@@ -188,7 +188,7 @@ module DangoFrameworkModule
188
188
  size_str = sock.recv(CommMaxDigit + 1)
189
189
  logger.debug "dango_receive_data:read header:sock=#{sock}"
190
190
 
191
- rescue EOFError, IOError, Errno::ECONNRESET, Errno::ETIMEDOUT, Errno::ECONNABORTED
191
+ rescue EOFError, IOError, Errno::ECONNRESET, Errno::ETIMEDOUT, Errno::ECONNABORTED, Errno::ENOTCONN
192
192
  # 接続終了時の切断と思われるものはDangoFrameworkConnectionExceptionにしない
193
193
  raise(DangoFrameworkDisconnectException, "failed to read sock for EOF reached (and so on). " +
194
194
  "sock=#{sock.inspect} #{$!.class} toid=#{Thread.current.object_id}")
@@ -249,6 +249,7 @@ module DangoFrameworkModule
249
249
  recv_data = receive_decrypt(recv_data_orig[0..-2])
250
250
 
251
251
  @recv_count += 1 if @recv_count # 受信回数カウント
252
+ @recv_byte += recv_data_orig.size if @recv_byte # 受信バイト数追加
252
253
 
253
254
  begin
254
255
  if recv_data == "" || recv_data == "{}" # データが空ならparseしない
@@ -311,6 +312,7 @@ module DangoFrameworkModule
311
312
  end
312
313
 
313
314
  @send_count += 1 if @send_count # 受信回数カウント
315
+ @send_byte += send_buf.size if @send_byte # 受信バイト数追加
314
316
 
315
317
  sock
316
318
  end
@@ -11,13 +11,18 @@ module ServerMonitorModule
11
11
  logger.debug "_monitor_get_server_info"
12
12
 
13
13
  get_server_info = {
14
- 'server_start_time' => start_time.strftime("%Y-%m-%d %H:%M:%S"),
15
- 'up_time' => Time.now - start_time,
14
+ 'server_start_time' => @start_time.strftime("%Y-%m-%d %H:%M:%S"),
15
+ 'server_up_time' => Time.now - @start_time,
16
+ 'server_version' => "#{Dango::VERSION::STRING} p#{Dango::VERSION::PATCH}(r#{RAILS_GEM_VERSION})",
16
17
 
17
- 'recv_count' => recv_count, # 受信回数
18
- 'send_count' => send_count, # 送信回数
19
- 'recv_fail_count' => recv_fail_count, # 受信失敗回数
20
- 'send_fail_count' => send_fail_count, # 送信失敗回数
18
+ 'recv_count' => @recv_count, # 受信回数
19
+ 'send_count' => @send_count, # 送信回数
20
+ 'recv_fail_count' => @recv_fail_count, # 受信失敗回数
21
+ 'send_fail_count' => @send_fail_count, # 送信失敗回数
22
+ 'recv_byte' => @recv_byte, # 受信バイト数
23
+ 'send_byte' => @send_byte, # 送信バイト数
24
+
25
+ 'mutex_fail_count' => @mutex_fail_count, # 送信失敗回数
21
26
 
22
27
  # 'log_level' => log_level_str,
23
28
  # 'log_file' => log_file,
@@ -76,23 +81,6 @@ module ServerMonitorModule
76
81
  })
77
82
  end
78
83
 
79
- # mutex_list = [
80
- # [:mutex_send_response, @mutex_send_response],
81
- # [:mutex_send_notice , @mutex_send_notice],
82
- # [:mutex_proc_thread , @mutex_proc_thread],
83
- # [:mutex_send_response, @mutex_send_response],
84
- # ]
85
- # @mutex_sock.each do |key, value|
86
- # mutex_list.push(["mutex_sock #{key}", value])
87
- # end
88
- #
89
- # mutex_list.each do |name, mutex|
90
- # ret.push({
91
- # :name => name.to_s,
92
- # :is_lock => mutex.locked?,
93
- # })
94
- # end
95
-
96
84
  ret
97
85
  end
98
86
 
@@ -127,5 +115,11 @@ module ServerMonitorModule
127
115
  ret
128
116
  end
129
117
 
118
+ # drbから呼ばれるメンテナンス:action_statの取得
119
+ def _monitor_get_action_stat(ret_obj)
120
+ logger.debug "_monitor_get_action_stat:#{ret_obj.inspect}"
121
+ @action_stat
122
+ end
123
+
130
124
  end
131
125
 
@@ -10,7 +10,6 @@ require "dango/framework_base"
10
10
  require "dango/socket_list"
11
11
  require "dango/version"
12
12
  require "dango/session_manager"
13
- #require "dango/monitor/server_monitor_action"
14
13
  require "dango/monitor/server_monitor_module"
15
14
  require "dango/default_dango_receive"
16
15
 
@@ -144,15 +143,20 @@ class DangoServerFramework
144
143
 
145
144
  require 'resolv-replace' if @safe_resolver # 名前解決時のロックがかかってしまう件を解決できるはず
146
145
 
147
- logger.warn("===== server initialize =====") # loggerの準備
148
- logger.warn("network_port=#{@network_port}")
149
- logger.warn("network_host=#{@network_host}")
150
- logger.warn("server_host=#{@server_host}")
151
- logger.warn("max_connections=#{@server_max_connections}")
152
- logger.warn("RAILS_ENV=#{RAILS_ENV}")
153
- logger.warn("Process.pid=#{Process.pid}")
154
- logger.warn("Dango Version=#{Dango::VERSION::STRING} p11")
155
- # logger.debug("$LOADED_FEATURES=#{$LOADED_FEATURES.pretty_inspect}")
146
+ if @no_start_log
147
+ logger.debug("===== no_start_log=#{@no_start_log.inspect} =====")
148
+ else
149
+ logger.warn("===== server initialize =====") # loggerの準備
150
+ logger.warn("network_port=#{@network_port}")
151
+ logger.warn("network_host=#{@network_host}")
152
+ logger.warn("server_host=#{@server_host}")
153
+ logger.warn("max_connections=#{@server_max_connections}")
154
+ logger.warn("RAILS_ENV=#{RAILS_ENV}")
155
+ logger.warn("Process.pid=#{Process.pid}")
156
+ logger.warn("Dango Version=#{Dango::VERSION::STRING} p#{Dango::VERSION::PATCH}")
157
+ logger.warn("Rails Version=#{RAILS_GEM_VERSION}")
158
+ # logger.debug("$LOADED_FEATURES=#{$LOADED_FEATURES.pretty_inspect}")
159
+ end
156
160
 
157
161
  shared_init() # 共有メモリを初期化
158
162
  socket_list_init() # ソケット一覧を初期化
@@ -177,8 +181,17 @@ class DangoServerFramework
177
181
  require "drb/acl"
178
182
  # uri = "druby://#{@network_host}:#{@backdoor_run_drb_port}"
179
183
  uri = @backdoor_run_drb_url
180
- list = ["deny", "all", "allow", @backdoor_host]
181
- acl = ACL.new(list, ACL::DENY_ALLOW)
184
+
185
+ allow_list = @backdoor_run_drb_allow_list.split(/\s+/)
186
+
187
+ acl_list = ["deny", "all"]
188
+ allow_list.each do |allow_host|
189
+ acl_list.push("allow")
190
+ acl_list.push(allow_host)
191
+ end
192
+ logger.info "drb acl_list=#{acl_list.inspect}"
193
+
194
+ acl = ACL.new(acl_list, ACL::DENY_ALLOW)
182
195
  @drb = DRb.start_service(uri, self, acl)
183
196
  # @drb = DRb.start_service(uri, self)
184
197
  DRb.thread[:_name] = "thread_drb_main"
@@ -387,19 +400,43 @@ class DangoServerFramework
387
400
  end
388
401
  session[:_return] = return_data
389
402
 
403
+ # アクションの統計情報情報の作成
404
+ if ! @action_stat.has_key?(action_name)
405
+ @action_stat[action_name] = {:total_sec => 0, :exec_count => 0, :fail_count => 0, }
406
+ end
407
+
408
+ # アクションの実行
390
409
  logger.debug "mpth:1:receive_action:session=#{sid} #{count}"
391
- @mutex_proc_thread.timeout_sync(4, "receive_action_#{action_name}") do
392
- logger.debug "mpth:2:receive_action:#{sid}:#{action_name}:"
393
- begin
394
- __send__("dango_receive_#{action_name}", ret_obj)
395
- rescue NoMethodError
396
- @recv_fail_count += 1 if @recv_fail_count # 受信失敗回数カウント
397
- logger.error "not find action #{action_name}:#{sid}:#{error_message($!, 'u')}"
398
- rescue DangoFrameworkTimeoutException
399
- logger.error "action is timeout:#{action_name}:#{sid}:#{error_message($!, 'u')}"
400
- end
401
-
402
- end # @mutex_proc_thread
410
+ begin
411
+ @mutex_proc_thread.timeout_sync(3, "receive_action_#{action_name}") do
412
+ logger.debug "mpth:2:receive_action:#{sid}:#{action_name}:"
413
+ begin
414
+ before_time = Time.now
415
+ __send__("dango_receive_#{action_name}", ret_obj)
416
+ send_sec = Time.now - before_time
417
+ @action_stat[action_name][:total_sec] = send_sec
418
+ @action_stat[action_name][:exec_count] += 1
419
+
420
+ rescue NoMethodError
421
+ @recv_fail_count += 1 if @recv_fail_count # 受信失敗回数カウント
422
+ @action_stat[action_name][:fail_count] += 1
423
+ logger.error "not find action #{action_name}:#{sid}:#{error_message($!, 'u')}"
424
+ rescue DangoFrameworkTimeoutException
425
+ @action_stat[action_name][:fail_count] += 1
426
+ logger.error "action is timeout:#{action_name}:#{sid}:#{error_message($!, 'u')}"
427
+ end
428
+
429
+ end # @mutex_proc_thread
430
+ rescue DangoFrameworkMutexTimeoutException
431
+ @mutex_fail_count += 1
432
+ @action_stat[action_name][:fail_count] += 1
433
+ logger.warn "receive_action DangoFrameworkMutexTimeoutException. #{sid} \n#{error_message($!, 'u')}"
434
+ raise(DangoFrameworkDisconnectException)
435
+ rescue Exception
436
+ logger.error "receive_action Exception #{sid} #{error_message($!, 'u')}"
437
+ @action_stat[action_name][:fail_count] += 1
438
+ raise(DangoFrameworkDisconnectException)
439
+ end
403
440
 
404
441
  # 不要になったセッション内のデータを削除(sidは再利用されるので消さない)
405
442
  session.delete(:_action_name)
@@ -408,17 +445,26 @@ class DangoServerFramework
408
445
 
409
446
  if ! session[:connected] # まだdango_connectを呼び出していないなら
410
447
  logger.debug "mpth:1:dango_connect"
411
- @mutex_proc_thread.timeout_sync(4, :dango_connect) do
412
- logger.debug "mpth:2:dango_connect"
413
- # 接続直後のsid通知
414
- send_obj = {"_sid"=>sid}
415
- send_notice("_notice_sid", sid, send_obj)
416
- logger.debug "_notice_sid #{sid} "
417
-
418
- dango_connect() # 接続時メソッド呼び出し
419
- session[:connected] = true
420
-
421
- end # mutex_proc_thread
448
+ begin
449
+ @mutex_proc_thread.timeout_sync(3, :dango_connect) do
450
+ logger.debug "mpth:2:dango_connect"
451
+ # 接続直後のsid通知
452
+ send_obj = {"_sid"=>sid}
453
+ send_notice("_notice_sid", sid, send_obj)
454
+ logger.debug "_notice_sid #{sid} "
455
+
456
+ dango_connect() # 接続時メソッド呼び出し
457
+ session[:connected] = true
458
+
459
+ end # mutex_proc_thread
460
+ rescue DangoFrameworkMutexTimeoutException
461
+ @mutex_fail_count += 1
462
+ logger.warn "receive_action DangoFrameworkMutexTimeoutException. #{sid} \n#{error_message($!, 'u')}"
463
+ raise(DangoFrameworkDisconnectException)
464
+ rescue Exception
465
+ logger.error "receive_action Exception #{sid} #{error_message($!, 'u')}"
466
+ raise(DangoFrameworkDisconnectException)
467
+ end
422
468
  end
423
469
  end
424
470
 
@@ -446,7 +492,11 @@ class DangoServerFramework
446
492
  rescue DangoFrameworkDisconnectException
447
493
  logger.debug "DangoFrameworkDisconnectException. #{sid} \n#{error_message($!, 'u')}"
448
494
 
495
+ rescue EOFError, IOError, Errno::ECONNRESET, Errno::ETIMEDOUT, Errno::ECONNABORTED, Errno::ENOTCONN
496
+ logger.debug "#{$!.class}. #{sid} maybe dissconnect exception \n#{error_message($!, 'u')}"
497
+
449
498
  rescue DangoFrameworkMutexTimeoutException
499
+ @mutex_fail_count += 1
450
500
  logger.warn "DangoFrameworkMutexTimeoutException. #{sid} \n#{error_message($!, 'u')}"
451
501
 
452
502
  rescue DangoFrameworkException
@@ -455,32 +505,47 @@ class DangoServerFramework
455
505
  rescue Exception
456
506
  logger.error "Exception #{sid} #{error_message($!, 'u')}"
457
507
 
458
- ensure
459
- # 接続切断の処理
460
-
508
+ end
509
+
510
+ # 接続切断の処理
511
+ begin
461
512
  if !is_flash_policy_file # Flash Policy Fileなら切断処理不要
462
513
  logger.info "#{sock.object_id} #{sid} is closing"
463
514
  if session[:connected] # dango_connect()が実行済みなら
464
515
  begin
465
- logger.debug "mpth:1:dango_close"
466
- @mutex_proc_thread.timeout_sync(4, :dango_close) do
467
- logger.debug "mpth:2:dango_close"
468
- dango_close() # 接続解除時に呼び出されるメソッド
469
-
470
- # ハートビートのごみを削除
471
- shared.transaction(:_heart_beat_time_hash) do |hbt_hash|
472
- hbt_hash.delete(sid)
473
- shared.commit(hbt_hash)
516
+ 5.times do |i| # リトライ用のループ
517
+ begin
518
+ need_retry = false
519
+ logger.debug "mpth:1:dango_close"
520
+ @mutex_proc_thread.timeout_sync(3, :dango_close) do
521
+ logger.debug "mpth:2:dango_close"
522
+ dango_close() # 接続解除時に呼び出されるメソッド
523
+
524
+ # ハートビートのごみを削除
525
+ shared.transaction(:_heart_beat_time_hash) do |hbt_hash|
526
+ hbt_hash.delete(sid)
527
+ shared.commit(hbt_hash)
528
+ end
529
+
530
+ end # mutex_proc_thread
531
+ logger.debug "dango_close end"
532
+
533
+ rescue DangoFrameworkMutexTimeoutException
534
+ need_retry = true
535
+ @mutex_fail_count += 1
536
+ logger.warn "dango_close DangoFrameworkMutexTimeoutException " +
537
+ "#{sock.object_id} #{sid} \n#{error_message($!, 'u')}"
474
538
  end
475
539
 
476
- end # mutex_proc_thread
477
- logger.debug "dango_close end"
478
-
479
- rescue DangoFrameworkMutexTimeoutException
480
- logger.warn "DangoFrameworkMutexTimeoutException " +
481
- "#{sock.object_id} #{sid} \n#{error_message($!, 'u')}"
540
+ if need_retry # リトライが必要と判断されれば
541
+ logger.warn "dango_close failed. need retry #{i}"
542
+ sleep(rand(5) + 5)
543
+ else # リトライ不要で落とすなら
544
+ break
545
+ end
546
+ end # times
482
547
  rescue Exception
483
- logger.error "#{sock.object_id} #{sid} ERROR\n#{error_message($!, 'u')}"
548
+ logger.error "dango_close #{sock.object_id} #{sid} ERROR\n#{error_message($!, 'u')}"
484
549
  end
485
550
  end
486
551
  end
@@ -492,6 +557,7 @@ class DangoServerFramework
492
557
  rescue IOError
493
558
  logger.info "IOError #{sock.object_id} #{sid}"
494
559
  rescue DangoFrameworkMutexTimeoutException
560
+ @mutex_fail_count += 1
495
561
  logger.warn "DangoFrameworkMutexTimeoutException #{sock.object_id} #{sid}\n" +
496
562
  "#{error_message($!, 'u')}"
497
563
  rescue Exception
@@ -508,15 +574,17 @@ class DangoServerFramework
508
574
  sock = nil # ソケット削除
509
575
  end
510
576
  rescue DangoFrameworkMutexTimeoutException
577
+ @mutex_fail_count += 1
511
578
  logger.warn "DangoFrameworkMutexTimeoutException #{sock.object_id} #{sid}\n" +
512
579
  "#{error_message($!, 'u')}"
513
- rescue Exception
514
- logger.error "#{sock.object_id} #{sid} Exception\n#{error_message($!, 'u')}"
515
580
  end
516
581
 
517
582
  @mutex_sock.delete(sock_object_id) # ソケット排他処理から削除
518
583
 
519
584
  @session_manager.close_session(sid) # sessionの終了処理
585
+
586
+ rescue Exception
587
+ logger.error "close process failed:#{sock.object_id} #{sid} Exception\n#{error_message($!, 'u')}"
520
588
  end
521
589
 
522
590
  end
@@ -583,15 +651,17 @@ EOF
583
651
  @policy_file_allow_port = @config['server']['policy_file_allow_port']
584
652
  @policy_file_allow_port = [@network_port] if !@policy_file_allow_port
585
653
 
586
- @safe_resolver = @config['server']['safe_resolver'] || false # require 'resolv-replace'するかどうか
654
+ @safe_resolver = @config['server']['safe_resolver'] || false # require 'resolv-replace'するかどうか
587
655
 
588
- @statistics_process_memory = @config['server']['statistics_process_memory'] || false # プロセスのメモリ使用量統計取る
656
+ @statistics_process_memory = @config['server']['statistics_process_memory'] || false # プロセスのメモリ使用量統計取る
589
657
 
590
- @backdoor_run_drb_server = @config['server']['backdoor_run_drb_server'] || false # drbサーバーを起動するか
591
- @backdoor_run_drb_url = @config['server']['backdoor_run_drb_url'] || 12345 # drbサーバーのポート番号
592
- @backdoor_host = @config['server']['backdoor_host'] || '127.0.0.1' # バックドアのアクセス可能ホスト名
658
+ @backdoor_run_drb_server = @config['server']['backdoor_run_drb_server'] || false # drbサーバーを起動するか
659
+ @backdoor_run_drb_url = @config['server']['backdoor_run_drb_url'] || 12345 # drbサーバーのポート番号
660
+ @backdoor_run_drb_allow_list = @config['server']['backdoor_run_drb_allow_list'] || '127.0.0.1 localhost' # アクセス可能ホスト名
593
661
 
594
- @loop_setting = @config['server']['loop_setting'] # メインループ用の定義
662
+ @loop_setting = @config['server']['loop_setting'] # メインループ用の定義
663
+
664
+ @no_start_log = @config['server']['no_start_log'] # メインループ用の定義
595
665
 
596
666
  # ログレベルの設定
597
667
  log_level_hash = {
@@ -619,10 +689,17 @@ EOF
619
689
  @send_count = 0 # 送信回数
620
690
  @recv_fail_count = 0 # 受信失敗回数
621
691
  @send_fail_count = 0 # 送信失敗回数
692
+ @recv_byte = 0 # 受信バイト数
693
+ @send_byte = 0 # 送信バイト数
694
+
695
+ @mutex_fail_count = 0 # 排他処理の失敗回数
696
+
697
+ @action_stat = {} # アクションの統計用
622
698
  end
623
699
 
624
- attr_reader(:start_time, :recv_count, :send_count, :recv_fail_count, :send_fail_count)
625
- attr_reader(:log_level_str, :log_file, :log_max_size, :log_shift_age)
700
+ # attr_reader(:start_time, :recv_count, :send_count, :recv_fail_count, :send_fail_count)
701
+ # attr_reader(:recv_byte, :send_byte, :mutex_fail_count, :action_stat)
702
+ # attr_reader(:log_level_str, :log_file, :log_max_size, :log_shift_age)
626
703
 
627
704
  def dango_server_init # 初期設定
628
705
  end
@@ -693,20 +770,23 @@ EOF
693
770
  begin
694
771
  sleep @gc_interval_sec
695
772
 
696
- logger.debug "mpth:1:GC start mutex start"
697
- @mutex_proc_thread.timeout_sync(4, :gc) do
698
- logger.debug "mpth:2:GC start #{Time.now_to_s}"
773
+ # logger.debug "mpth:1:GC start mutex start"
774
+ # @mutex_proc_thread.timeout_sync(3, :gc) do
775
+ # logger.debug "mpth:2:GC start #{Time.now_to_s}"
776
+
777
+ logger.debug "GC start mutex start"
699
778
  gc_start_time = Time.now
700
779
  GC.enable
701
780
  GC.start
702
781
  GC.disable
703
782
  logger.debug "GC end #{Time.now - gc_start_time}sec "
704
- end
783
+ # end
705
784
  logger.debug "GC start mutex end"
706
785
 
707
786
  output_memory_statistics() if @statistics_process_memory # メモリ使用量統計
708
787
 
709
788
  rescue DangoFrameworkMutexTimeoutException
789
+ @mutex_fail_count += 1
710
790
  logger.warn "DangoFrameworkMutexTimeoutException gc_thread_start" +
711
791
  "#{error_message($!, 'u')}"
712
792
  rescue Exception
@@ -752,9 +832,18 @@ EOF
752
832
 
753
833
  next if @gserver.stopped? # gserverが起動していればスキップ
754
834
 
755
- logger.debug "mpth:1:heart_beat_thread_start "
756
- @mutex_proc_thread.timeout_sync(4, :heart_beat_thread) do
757
- logger.debug "mpth:2:heart_beat_thread_start "
835
+ # logger.debug "mpth:1:heart_beat_thread_start "
836
+ # @mutex_proc_thread.timeout_sync(3, :heart_beat_thread) do
837
+ # logger.debug "mpth:2:heart_beat_thread_start "
838
+
839
+ # 古いハートビート情報は先に削除しておく
840
+ shared.transaction(:_heart_beat_time_hash) do |hbt_hash|
841
+ hbt_hash.keys.each do |sid|
842
+ hbt_hash.delete(sid) if hbt_hash[sid] < Time.now - @heart_beat_receive_wait_sec * 30
843
+ end
844
+ shared.commit(hbt_hash)
845
+ end
846
+
758
847
  # クライアントから来るハートビートのチェック
759
848
  heart_beat_time_hash = shared[:_heart_beat_time_hash]
760
849
 
@@ -796,10 +885,11 @@ EOF
796
885
  end
797
886
  end # socket_list
798
887
 
799
- end # @mutex_proc_thread
888
+ # end # @mutex_proc_thread
800
889
  logger.debug "heart_beat_thread_start end"
801
890
 
802
891
  rescue DangoFrameworkMutexTimeoutException
892
+ @mutex_fail_count += 1
803
893
  logger.warn "DangoFrameworkMutexTimeoutException heart_beat_thread_start" +
804
894
  "#{error_message($!, 'u')}"
805
895
  rescue Exception
@@ -848,6 +938,7 @@ EOF
848
938
  @queue_send_notice.push([sid, send_obj_dup, encode_type].deep_dup)
849
939
  end
850
940
  rescue DangoFrameworkMutexTimeoutException
941
+ @mutex_fail_count += 1
851
942
  logger.warn "mutex_send_notice #{error_message($!, 'u')}"
852
943
  rescue Exception
853
944
  logger.error "mutex_send_notice #{error_message($!, 'u')}"
@@ -915,6 +1006,7 @@ EOF
915
1006
  logger.info "thread_send_notice_queue:failed send. sid=#{sid} " +
916
1007
  "sock=#{sock.object_id} #{$!.class}"
917
1008
  rescue DangoFrameworkMutexTimeoutException
1009
+ @mutex_fail_count += 1
918
1010
  logger.warn "thread_send_notice_queue:failed send. sid=#{sid} " +
919
1011
  "sock=#{sock.object_id} #{$!.class}"
920
1012
  rescue Exception
@@ -931,6 +1023,7 @@ EOF
931
1023
  sleep @send_receive_sleep_interval_sec # スリープ
932
1024
 
933
1025
  rescue DangoFrameworkMutexTimeoutException
1026
+ @mutex_fail_count += 1
934
1027
  logger.warn "ERROR:thread_send_notice_queue:DangoFrameworkMutexTimeoutException" +
935
1028
  "#{error_message($!, 'u')}"
936
1029
  rescue Exception
@@ -958,7 +1051,7 @@ EOF
958
1051
  end
959
1052
 
960
1053
  # メインループ用の定義をするためのメソッド
961
- def set_loop_setting(options={})
1054
+ def set_loop_setting(options = {})
962
1055
  options = options.deep_dup
963
1056
 
964
1057
  shared[:_is_server_sleep] = nil # メンテナンス停止用
@@ -974,29 +1067,39 @@ EOF
974
1067
  logger.debug "set_loop_setting start"
975
1068
  count = 0
976
1069
 
1070
+ last_mutex_fail_count = @mutex_fail_count.deep_dup # 前回のmutex_fail_countを記録する
1071
+
977
1072
  loop do
978
1073
  begin
979
1074
  before_time = Time.now
980
1075
 
981
1076
  logger.debug "mpth:1:sls start"
982
- @mutex_proc_thread.timeout_sync(4, "set_loop_setting_send_#{method_name}") do
1077
+ @mutex_proc_thread.timeout_sync(3, "set_loop_setting_send_#{method_name}") do
983
1078
  __send__(method_name)
984
1079
  end # mutex_proc_thread
985
1080
  logger.debug "mpth:2:sls end"
986
1081
  # if count % 1000 == 0
987
1082
 
988
1083
  real_wait_sec = wait_sec - (Time.now - before_time)
1084
+ logger.debug "set_loop_setting:compute time=#{real_wait_sec - wait_sec}" if real_wait_sec < 0
989
1085
  sleep real_wait_sec if real_wait_sec > 0
990
1086
 
991
1087
  count += 1
992
1088
  count = 0 if count >= 10000000
993
1089
 
1090
+ # mutex_fail_countが増えたらサーバーが重くなりすぎていると判断してちょっと待つ
1091
+ if @mutex_fail_count > last_mutex_fail_count
1092
+ sleep 1
1093
+ last_mutex_fail_count = @mutex_fail_count.deep_dup
1094
+ end
1095
+
994
1096
  # メンテナンス機能
995
1097
  if shared[:_is_server_sleep]
996
1098
  logger.info "set_loop_setting SLEEP !!!"
997
1099
  sleep 10000
998
1100
  end
999
1101
  rescue DangoFrameworkMutexTimeoutException
1102
+ @mutex_fail_count += 1
1000
1103
  logger.warn "set_loop_setting error:#{error_message($!, 'u')}"
1001
1104
  rescue Exception
1002
1105
  logger.error "set_loop_setting error:#{error_message($!, 'u')}"
@@ -42,8 +42,8 @@ module DangoFrameworkModule
42
42
  raise(DangoFrameworkException, "Shared key is not exist.")
43
43
  end
44
44
 
45
- # @mutex[key].timeout_sync(3, "transaction_old #{key}") do
46
- @mutex.timeout_sync(3, "transaction_old") do
45
+ # @mutex[key].timeout_sync(2, "transaction_old #{key}") do
46
+ @mutex.timeout_sync(2, "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].timeout_sync(3, "transaction #{key}") do
70
- # @mutex.timeout_sync(3, "transaction") do
69
+ @mutex[key].timeout_sync(2, "transaction #{key}") do
70
+ # @mutex.timeout_sync(2, "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].timeout_sync(3, "[] #{key}") do
152
- # @mutex.timeout_sync(3, "[]") do
151
+ @mutex[key].timeout_sync(2, "[] #{key}") do
152
+ # @mutex.timeout_sync(2, "[]") do
153
153
  @data[key].deep_dup
154
154
  end
155
155
  end
@@ -169,8 +169,8 @@ module DangoFrameworkModule
169
169
  end
170
170
 
171
171
  # ロックしてデータを入れる
172
- @mutex[key].timeout_sync(3, "[]= #{key}") do
173
- # @mutex.timeout_sync(3, "[]=") do
172
+ @mutex[key].timeout_sync(2, "[]= #{key}") do
173
+ # @mutex.timeout_sync(2, "[]=") do
174
174
  @data[key] = value.deep_dup
175
175
  end
176
176
 
@@ -8,19 +8,19 @@ class SocketList
8
8
  end
9
9
 
10
10
  def all_sid()
11
- @sl_mutex.timeout_sync(4, :all_sid) do
11
+ @sl_mutex.timeout_sync(2, :all_sid) do
12
12
  @sl_hash.keys
13
13
  end
14
14
  end
15
15
 
16
16
  def delete(sid)
17
- @sl_mutex.timeout_sync(4, :delete) do
17
+ @sl_mutex.timeout_sync(2, :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.timeout_sync(4, :add) do
23
+ @sl_mutex.timeout_sync(2, :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.timeout_sync(4, "[]") do
31
+ @sl_mutex.timeout_sync(2, "[]") 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]
@@ -1,6 +1,8 @@
1
1
  # 環境変数設定
2
2
  ENV['RAILS_ENV'] = ENV['RAILS_ENV'] || 'development'
3
3
 
4
+ $KCODE = "u"
5
+
4
6
  require "pp"
5
7
  require "timeout"
6
8
  require "yaml"
@@ -153,29 +155,35 @@ class DangoRakeUtil
153
155
 
154
156
  sid = nil
155
157
 
156
- begin
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
158
+ tester = DangoTesterClient.new # 開始
159
+ 3.times do |i| # 3回接続確認する
160
+ begin
161
+ tester1 = nil
162
+ timeout(6) do
163
+ tester1 = tester.new_client("tester1", serv_info) # テスター1
164
+
165
+ 5.times do |j|
166
+ sleep 1
167
+ sid = tester1.sid.deep_dup
168
+ tester1.logger.warn "count=#{j} sid=#{sid}"
169
+ puts_verbose "count=#{j} sid=#{sid}"
170
+ break if sid
171
+ end
172
+ tester1.dango_client_close if tester1.respond_to?(:dango_client_close)
167
173
  end
174
+ rescue TimeoutError
175
+ sid = nil
176
+ puts_verbose "DangoTesterClient.TimeoutError"
168
177
  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)
178
+
174
179
  tester1 = nil
175
- tester.gc_thread_stop
180
+
181
+ break if sid # 接続に成功していたらスキップ
182
+
183
+ puts_verbose "test connect failed #{i}"
176
184
  end
177
185
 
178
- puts_verbose "sid=#{sid.inspect}"
186
+ tester.gc_thread_stop
179
187
 
180
188
  if sid
181
189
  is_alive_server = true
@@ -325,40 +333,89 @@ namespace :dango do
325
333
  dru.check_verbose_mode() # verboseモードのフラグを立てる処理
326
334
  dru.puts_noverbose "check_dango_process"
327
335
 
336
+ # サーバーを再起動するかどうかの判定
328
337
  pid = dru.get_dango_pid() # pidのチェック
329
338
  is_pid_exist = dru.check_exist_dango_process(pid) # pidのプロセスがあるかどうかのチェック
330
339
  is_alive_server = dru.check_dango_connect() if is_pid_exist # サーバーへの通信を使ったチェック
331
340
 
332
- # コンフィグから check_dango_process_cmd を取得
333
- config = YAML.load(open("#{RAILS_ROOT}/config/dango/#{ENV['RAILS_ENV']}.yml", "rb"){|fh| fh.read})
334
- check_dango_process_cmd = config['server']['check_dango_process_cmd'] || nil
341
+ sleep 1
335
342
 
336
- # is_pid_existがないならcheck_dango_process_cmd実行
337
- if check_dango_process_cmd && (! is_alive_server)
338
- if pid # pidがあればプロセス停止
339
- dru.get_trouble_status(config, pid) # 落ちた時の情報収集処理
343
+ if is_alive_server
344
+ # サーバーが生きている場合
345
+ dru.puts_noverbose "server is alive. is_alive_server=#{is_alive_server.inspect}"
346
+
347
+ # コンフィグから check_dango_process_cmd を取得
348
+ config = YAML.load(open("#{RAILS_ROOT}/config/dango/#{ENV['RAILS_ENV']}.yml", "rb"){|fh| fh.read})
349
+ begin
350
+ check_dango_process_cmd = config['server']['check_dango_process']['long_alive_restart_cmd'] || nil
351
+ long_alive_minutes = config['server']['check_dango_process']['long_alive_minutes'] || 7 * 24 * 60
352
+ rescue
353
+ check_dango_process_cmd = nil
354
+ long_alive_minutes = 7 * 24 * 60
355
+ end
356
+
357
+ # サーバーの起動時間をチェック
358
+ server_info = dru.drb_call(:_monitor_get_server_info)
359
+ socket_list = dru.drb_call(:_monitor_get_socket_list)
360
+
361
+ dru.puts_noverbose "server_up_time=#{server_info['server_up_time'].inspect} " +
362
+ "socket_list.size=#{socket_list.size}"
363
+
364
+ # サーバーが長く起動していて、接続者がいないのなら
365
+ if check_dango_process_cmd &&
366
+ server_info['server_up_time'].to_i > long_alive_minutes * 60 &&
367
+ socket_list.size == 0
368
+
369
+ dru.puts_noverbose "long alive restart."
340
370
 
341
- dru.stop_process(pid)
371
+ # プロセス停止
372
+ dru.stop_process(pid)
373
+
374
+ # サーバーが止まっているので起動処理をかける
375
+ dru.puts_verbose "check_dango_process_cmd=#{check_dango_process_cmd}"
376
+ system(check_dango_process_cmd)
377
+ end
378
+
379
+ # テスト接続のログがあればそれを削除する
380
+ if File.file?(DangoRakeUtil::CheckConnectLogFile)
381
+ FileUtils.rm_f([DangoRakeUtil::CheckConnectLogFile])
342
382
  end
343
- end
344
-
345
- # テスト接続のログがあればそれを削除する
346
- if File.file?(DangoRakeUtil::CheckConnectLogFile)
347
- FileUtils.rm_f([DangoRakeUtil::CheckConnectLogFile])
348
- end
349
-
350
- # サーバーが止まっているので起動処理をかける
351
- if check_dango_process_cmd && ((! is_pid_exist) || (! is_alive_server))
352
- dru.puts_verbose "check_dango_process_cmd=#{check_dango_process_cmd}"
353
383
 
354
- # tmp/pidsから
384
+ else
385
+ # サーバーが死んでいた場合
386
+ dru.puts_noverbose "server is dead. is_alive_server=#{is_alive_server.inspect}"
387
+
388
+ # コンフィグから check_dango_process_cmd を取得
355
389
  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
390
+ begin
391
+ check_dango_process_cmd = config['server']['check_dango_process']['normal_restart_cmd'] || nil
392
+ rescue
393
+ check_dango_process_cmd = nil
394
+ end
357
395
 
358
- system(check_dango_process_cmd)
396
+ # is_pid_existがないなら情報収集してから、サーバーを再起動する
397
+ if check_dango_process_cmd
398
+ if pid # pidがあれば
399
+ # 落ちた時の情報収集処理
400
+ dru.get_trouble_status(config, pid)
401
+
402
+ # プロセス停止
403
+ dru.stop_process(pid)
404
+ end
405
+
406
+ # サーバーが止まっているので起動処理をかける
407
+ dru.puts_verbose "check_dango_process_cmd=#{check_dango_process_cmd}"
408
+ system(check_dango_process_cmd)
409
+ end
410
+
411
+ # テスト接続のログがあればそれを削除する
412
+ if File.file?(DangoRakeUtil::CheckConnectLogFile)
413
+ FileUtils.rm_f([DangoRakeUtil::CheckConnectLogFile])
414
+ end
415
+
416
+ dru.puts_noverbose "complete check_dango_process."
359
417
  end
360
418
 
361
- dru.puts_noverbose "complete check_dango_process."
362
419
  end
363
420
 
364
421
  desc "get_trouble_status"
@@ -436,6 +493,14 @@ namespace :dango do
436
493
  pp dru.drb_call(:_monitor_get_session_list)
437
494
  end
438
495
 
496
+ desc "get_action_stat"
497
+ task :get_action_stat do
498
+ dru = DangoRakeUtil.new
499
+ dru.check_verbose_mode() # verboseモードのフラグを立てる処理
500
+ dru.puts_noverbose "get_action_stat"
501
+ pp dru.drb_call(:_monitor_get_action_stat)
502
+ end
503
+
439
504
  desc "server_reload" # サーバーのリロード処理
440
505
  task :server_reload do
441
506
  dru = DangoRakeUtil.new
@@ -212,7 +212,6 @@ class TestClient < DangoClientFramework
212
212
  logger.debug "ret_obj:#{name}:" + ret_obj.inspect + " " + Time.now_to_s
213
213
  send_receive_shared.transaction(:receive_cache) do |receive_cache|
214
214
  receive_cache.push([name, ret_obj, Time.now])
215
- receive_cache
216
215
  send_receive_shared.commit(receive_cache)
217
216
  end
218
217
 
@@ -264,18 +263,14 @@ class TestClient < DangoClientFramework
264
263
  # 結果を削除しておく
265
264
  send_receive_shared.transaction(:receive_cache) do |receive_cache|
266
265
  receive_cache.delete_at(receive_idx)
267
- receive_cache
268
266
  send_receive_shared.commit(receive_cache)
269
267
  end
270
268
 
271
269
  # 古いreceive_cacheを削除しておく
272
270
  send_receive_shared.transaction(:receive_cache) do |receive_cache|
273
271
  receive_cache = receive_cache.select do |one_receive_cache|
274
- # true
275
272
  one_receive_cache[2] > Time.now - @receive_cache_auto_delete_sec
276
273
  end
277
-
278
- receive_cache
279
274
  send_receive_shared.commit(receive_cache)
280
275
  end
281
276
 
@@ -284,14 +279,13 @@ class TestClient < DangoClientFramework
284
279
 
285
280
  # clear_receive notice_nameを省略するとchacheにあるものすべて削除
286
281
  def clear_receive(notice_name = nil, options = {})
287
- logger.debug "wait_receive_data:#{notice_name}:"
282
+ logger.debug "clear_receive:#{notice_name}:"
288
283
 
289
284
  # 結果を削除しておく
290
285
  send_receive_shared.transaction(:receive_cache) do |receive_cache|
291
286
  receive_cache.delete_if do |one_rec_data|
292
287
  true if (! notice_name) || (notice_name && one_rec_data[0] == notice_name)
293
288
  end
294
- receive_cache
295
289
  send_receive_shared.commit(receive_cache)
296
290
  end
297
291
  end
data/lib/dango/version.rb CHANGED
@@ -2,8 +2,10 @@ module Dango #:nodoc:
2
2
  module VERSION #:nodoc:
3
3
  MAJOR = 0
4
4
  MINOR = 5
5
- TINY = 0
6
-
5
+ TINY = 1
6
+
7
7
  STRING = [MAJOR, MINOR, TINY].join('.')
8
+
9
+ PATCH = 0
8
10
  end
9
11
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dango
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.0
4
+ version: 0.5.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Keisuke Minami
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2008-11-05 00:00:00 +09:00
12
+ date: 2008-12-01 00:00:00 +09:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -66,7 +66,6 @@ files:
66
66
  - lib/dango/default_dango_receive.rb
67
67
  - lib/dango/controller_plugin/dango_controller_plugin.rb
68
68
  - lib/dango/monitor/dango_monitor_client.rb
69
- - lib/dango/monitor/server_monitor_action.rb
70
69
  - lib/dango/monitor/server_monitor_module.rb
71
70
  - lib/dango/script/dango_server.rb
72
71
  - lib/dango/shared/memory_store.rb
@@ -1,148 +0,0 @@
1
- #!ruby -Ku
2
-
3
- =begin
4
- = Dangoサーバーのメンテナンス用サーバー側機能
5
- =end
6
-
7
- require 'ipaddr'
8
-
9
- # メインクラス
10
- class ServerMonitorAction
11
- def initialize(parent, config, peerhost, peeraddr, ret_obj)
12
- @parent = parent
13
- @config = config
14
-
15
- @logger = @parent.logger
16
- @shared = @parent.shared
17
- @session = @parent.session
18
- @socket_list = @parent.socket_list
19
- @session_list = @parent.session_list
20
-
21
- # アクション名
22
- action_name = ret_obj["action"].to_s
23
-
24
- dango_check_monitor_error(peerhost, peeraddr, action_name)
25
-
26
- if action_name == '_monitor_all_info' # メンテナンスアクション名なら
27
- dango_server_monitor_all_info(ret_obj)
28
-
29
- elsif action_name == '_monitor_get_server_info' # メンテナンスアクション名なら
30
- dango_server_monitor_get_server_info(ret_obj)
31
-
32
- elsif action_name == '_monitor_get_shared' # メンテナンスアクション名なら
33
- dango_server_monitor_get_shared(ret_obj)
34
-
35
- elsif action_name == '_monitor_get_session_list' # メンテナンスアクション名なら
36
- dango_server_monitor_get_session_list(ret_obj)
37
-
38
- elsif action_name == '_monitor_get_socket_list' # メンテナンスアクション名なら
39
- dango_server_monitor_get_socket_list(ret_obj)
40
-
41
- elsif action_name == '_monitor_send_system_message' # メンテナンスアクション名なら
42
- dango_server_monitor_send_system_message(ret_obj)
43
-
44
- else
45
- end
46
- end
47
-
48
- attr_reader(:logger, :shared, :session, :socket_list, :session_list)
49
-
50
- private
51
-
52
- # メンテナンスコマンド:エラーの場合
53
- def dango_check_monitor_error(peerhost, peeraddr, action_name)
54
- backdoor_host = @backdoor_host
55
- logger.debug "dango_check_monitor_error:peerhost=#{peerhost.inspect} peeraddr=#{peeraddr.inspect} backdoor_host=#{backdoor_host.inspect}"
56
-
57
- match = false
58
- if peerhost == backdoor_host # ホスト名で書いてある時の一致確認
59
- match = true
60
- else
61
- begin # IPアドレスの一致確認
62
- # match = true if IPAddr.new(backdoor_host).include?(peeraddr)
63
- if IPAddr.new(backdoor_host).include?(IPAddr.new(peeraddr))
64
- match = true
65
- end
66
- rescue
67
- end
68
- end
69
-
70
- if !match
71
- notice_name = "return_" + action_name
72
- send_obj = {'code'=>1, 'message'=>"error your ip address"}
73
- @parent.send_notice(notice_name, session[:sid], send_obj, :type=>2)
74
- raise(DangoFrameworkMonitorSecurityError)
75
- end
76
- end
77
-
78
- # メンテナンスコマンド:サーバーからクライアントへのデータ送信
79
- def dango_server_monitor_get_server_info(ret_obj)
80
- logger.debug "dango_server_monitor_get_server_info:#{ret_obj.inspect}"
81
- get_server_info = {
82
- 'server_start_time' => @parent.start_time.strftime("%Y-%m-%d %H:%M:%S"),
83
- 'up_time' => Time.now - @parent.start_time,
84
-
85
- 'recv_count' => @parent.recv_count, # 受信回数
86
- 'send_count' => @parent.send_count, # 送信回数
87
- 'recv_fail_count' => @parent.recv_fail_count, # 受信失敗回数
88
- 'send_fail_count' => @parent.send_fail_count, # 送信失敗回数
89
-
90
- 'log_level' => @parent.log_level_str,
91
- 'log_file' => @parent.log_file,
92
- 'log_max_size' => @parent.log_max_size,
93
- 'log_shift_age' => @parent.log_shift_age,
94
- }
95
-
96
- send_obj = {'code'=>0, 'get_server_info'=>get_server_info}
97
- @parent.send_notice('return__monitor_get_server_info', session[:sid], send_obj, :type=>2)
98
- end
99
-
100
- # メンテナンスコマンド:サーバーからクライアントへのデータ送信
101
- def dango_server_monitor_get_shared(ret_obj)
102
- logger.debug "dango_server_monitor_get_shared:#{ret_obj.inspect}"
103
- send_obj = {'code'=>0, 'get_shared'=>shared.to_hash}
104
- @parent.send_notice('return__monitor_get_shared', session[:sid], send_obj, :type=>2)
105
- end
106
-
107
- # メンテナンスコマンド:サーバーからクライアントへのデータ送信
108
- def dango_server_monitor_get_session_list(ret_obj)
109
- logger.debug "dango_server_monitor_get_session_list:#{ret_obj.inspect}"
110
- send_obj = {'code'=>0, 'get_session_list'=>session_list}
111
- @parent.send_notice('return__monitor_get_session_list', session[:sid], send_obj, :type=>2)
112
- end
113
-
114
- # メンテナンスコマンド:サーバーからクライアントへのデータ送信
115
- def dango_server_monitor_get_socket_list(ret_obj)
116
- logger.debug "dango_server_monitor_get_socket_list:#{ret_obj.inspect}"
117
- send_obj = {'code'=>0, 'get_socket_list'=>socket_list.keys}
118
- @parent.send_notice('return__monitor_get_socket_list', session[:sid], send_obj, :type=>2)
119
- end
120
-
121
- # メンテナンスコマンド:サーバーデータ再読み込み
122
- def dango_server_monitor_server_reload(ret_obj)
123
- logger.debug "dango_server_monitor_server_reload"
124
- @server_reload = true
125
- logger.debug "@server_reload=#{@server_reload.inspect}"
126
- send_obj = {'code'=>0, 'message'=>'success'}
127
- @parent.send_notice('return__monitor_server_reload', session[:sid], send_obj, :type=>2)
128
- end
129
-
130
- # メンテナンスコマンド:接続者全員へメッセージ送信
131
- def dango_server_monitor_send_system_message(ret_obj)
132
- logger.debug "dango_server_monitor_send_system_message:#{ret_obj.inspect}"
133
-
134
- # 全員へ_notice_system_messageを通知
135
- socket_list.keys.each do |sid|
136
- next if session[:sid] == sid
137
- send_obj = { "message" => ret_obj["message"] }
138
- @parent.send_notice('_notice_system_message', sid, send_obj)
139
- end
140
-
141
- send_obj = {'code'=>0, }
142
- @parent.send_notice('return__monitor_send_system_message', session[:sid], send_obj, :type=>2)
143
- end
144
-
145
- end
146
-
147
-
148
-