Web サービスが停止していないかどうか確認するスクリプト。 open-uri を使うとタイムアウトが設定できないので、net/http で行う。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
| require 'net/http' PROXY_ADDRESS = nil \ PROXY_PORT = nil \ def check\_site\_alive(domain, port = 80) begin Net::HTTP.start(domain, port, PROXY_ADDRESS, PROXY_PORT) do |http| http.open_timeout = 20 http.read_timeout = 40 \ response = http.post(path, data) return response.code == '200' end rescue Exception =\> e puts e return false end end puts check\_site\_alive("webservice.domain")
|
tilfin
freelance software engineer