Class | Control |
In: |
lib/control.rb
|
Parent: | Object |
Class to send SCGI control message on socket. It also receive and parse the acknowledge message.
Constructor.
# File lib/control.rb, line 28 28: def initialize(name) 29: @name=name # Application name 30: @req = SCGI.new # SCGI control message 31: @req.header_add("component","APPLICATION") 32: @req.header_add("app_name",@name) 33: end
Send control message to deploy newly added Applicaiton.
# File lib/control.rb, line 41 41: def add 42: @req.header_add("method","ADD") 43: send_control 44: end
Send control message to stop Applicaiton.
# File lib/control.rb, line 47 47: def delete 48: @req.header_add("method","REMOVE") 49: send_control 50: end
Send control message to refresh Applicaiton.
# File lib/control.rb, line 53 53: def restart 54: @req.header_add("method","RELOAD") 55: send_control 56: end
Build and send SCGI control message.
# File lib/control.rb, line 59 59: def send_control 60: @req.build 61: sockFile = File.join("","tmp","webroar.sock") 62: 63: if !File.exist?(sockFile) 64: return "Either altas-server is not started or 'webroar.sock' file is deleted." 65: end 66: 67: file = File.new(sockFile) 68: port = file.gets 69: file.close 70: if(port.to_i == 0) 71: streamSock = UNIXSocket.new(port) 72: else 73: streamSock = TCPSocket.new( "127.0.0.1", port.to_i) 74: end 75: streamSock.send(@req.request, 0) 76: str = streamSock.recv(2048) 77: streamSock.close 78: @resp = SCGI.new 79: @resp.parse(str) 80: 81: if @resp.header("STATUS") == "OK" or @resp.header("STATUS") == "ok" 82: return nil 83: else 84: if @resp.body == nil 85: return "Error: Operation not performed." 86: else 87: return @resp.body 88: end 89: end 90: end