Top Level Namespace

Defined Under Namespace

Modules: Dango, DangoControllerPlugin, DangoFrameworkModule, DangoUtilModule, ErrorMessage Classes: DangoClientFramework, DangoFrameworkConnectionException, DangoFrameworkDisconnectException, DangoFrameworkException, DangoFrameworkFlashPolicyException, DangoFrameworkMonitorSecurityException, DangoFrameworkReadNoDataException, DangoFrameworkReadTimeoutException, DangoFrameworkTimeoutException, DangoFrameworkTransactionException, DangoGServer, DangoMonitorClient, DangoServerFramework, DangoTesterClient, GServer, Object, ScriptDangoServer, ServerMonitorAction, SessionManager, SocketList, TestClient, Time

Instance Method Summary collapse

Instance Method Details

#check_dango_connectObject

サーバーへの通信を使ったチェック



91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
# File 'lib/dango/tasks/dango_rake.rb', line 91

def check_dango_connect()
  require 'dango/tester/dango_tester_client'
  
  # コンフィグから check_dango_process_cmd を取得
  config = YAML.load(open("config/dango/#{ENV['RAILS_ENV']}.yml", "rb"){|fh| fh.read})
  
  serv_info = {}
  serv_info["host"] = config['network']['host'] || 'localhost'
  serv_info["port"] = config['network']['port'] || 15000
  serv_info["log_file"] = ""
  serv_info["log_level"] = Logger::WARN
  serv_info["log_max_size"] = 10000000
  serv_info["log_shift_age"] = 10

#  pp serv_info
  
  tester = DangoTesterClient.new # 開始
  
  begin
    tester1 = nil
    sid = nil
    timeout(8) do
      tester1 = tester.new_client("tester1", serv_info) # テスター1
      
      sleep 3
      loop do
        sid = tester1.sid
        break if sid
        sleep 1
      end
    end
  rescue TimeoutError
    sid = nil
  ensure
    tester1.dango_client_close if tester1.respond_to?(:dango_client_close)
    tester1 = nil
    tester.gc_thread_stop
  end
  
  puts "sid=#{sid.inspect}" if $is_verbose
  
  if sid
    is_alive_server = true
  else
    is_alive_server = false
  end
  
  is_alive_server
end

#check_exist_dango_process(pid) ⇒ Object

pidのプロセスがあるかどうかのチェック



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/dango/tasks/dango_rake.rb', line 25

def check_exist_dango_process(pid)
  puts "check_exist_dango_process(pid=#{pid})" if $is_verbose
  
  # そのpidのプロセスがあるかのチェック
  is_pid_exist = nil
  
  if RUBY_PLATFORM == 'i386-mswin32'
    # WbemからProcessIDを取得
    require "win32ole"
    begin
      n_locator = WIN32OLE.new("WbemScripting.SWbemLocator.1")
      n_service = n_locator.ConnectServer
    rescue
      puts "failed connect to Wbem:#{$!.inspect}" if $is_verbose
      return
    end
    
    set = n_service.ExecQuery("select Caption, ProcessID from Win32_Process where ProcessID = #{pid}")
    set.each do |one|
#      puts(sprintf("Win32_Process %8d %s", one.ProcessID, one.Caption))
      if one.ProcessID == pid
        is_pid_exist = true
      end
    end
    
  else ## i386-mswin32以外
    is_pid_exist = FileTest.exist?("/proc/#{pid}")
  end
  
  if is_pid_exist
    puts "dango_process is exist." if $is_verbose
  else
    puts "dango_process is not exist." if $is_verbose
  end
  
  is_pid_exist
end

#check_verbose_modeObject

verboseモードのフラグを立てる処理



9
10
11
# File 'lib/dango/tasks/dango_rake.rb', line 9

def check_verbose_mode()
  $is_verbose = (ENV["verbose"] == "true" || ENV["verbose"] == "on") ? true : false
end

#get_dango_pidObject

pid保存ファイルの読み出し



14
15
16
17
18
19
20
21
22
# File 'lib/dango/tasks/dango_rake.rb', line 14

def get_dango_pid()
  begin
    pid = open("tmp/pids/dango.#{ENV['RAILS_ENV']}.pid", "rb"){|fh| fh.read }.to_i
  rescue
    pid = nil
  end
  puts "pid=#{pid.inspect}" if $is_verbose
  pid
end

#stop_process(pid) ⇒ Object

プロセス停止



64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
# File 'lib/dango/tasks/dango_rake.rb', line 64

def stop_process(pid)
  puts "stop process (pid=#{pid})" if $is_verbose
  
  if RUBY_PLATFORM == 'i386-mswin32'
    # WbemからProcessIDを取得
    require "win32ole"
    begin
      n_locator = WIN32OLE.new("WbemScripting.SWbemLocator.1")
      n_service = n_locator.ConnectServer
    rescue
      puts "failed connect to Wbem:#{$!.inspect}" if $is_verbose
      return
    end
    
    set = n_service.ExecQuery("select Caption, name, ProcessID from Win32_Process where ProcessID = '#{pid}'")
    set.each do |process|
      puts "stopping #{process.Caption} #{process.name} #{process.ProcessID}" if $is_verbose
      process.Terminate 0
    end
    
  else ## i386-mswin32以外
#    system("kill -9 #{pid}")
    system("kill #{pid}")
  end
end