Skip to content

Instantly share code, notes, and snippets.

@jordansissel
Created Oct 11, 2010
Embed
What would you like to do?
% sudo ruby ruby-supervisorctl.rb
[
[0] [
[0] {
:state => 30,
:stdout_logfile => "/tmp/falsetest-stdout---supervisor-bqdUwO.log",
:now => 1286783537,
:start => 1286783530,
:group => "falsetest",
:stderr_logfile => "/tmp/falsetest-stderr---supervisor-1kKclr.log",
:logfile => "/tmp/falsetest-stdout---supervisor-bqdUwO.log",
:pid => 0,
:description => "Exited too quickly (process log may have details)",
:spawnerr => "Exited too quickly (process log may have details)",
:stop => 1286783530,
:name => "falsetest",
:statename => "BACKOFF",
:exitstatus => 0
},
[1] {
:state => 10,
:stdout_logfile => "/tmp/mysqld-stdout---supervisor-ZEfmqr.log",
:now => 1286783537,
:start => 1286783536,
:group => "mysqld",
:stderr_logfile => "/tmp/mysqld-stderr---supervisor-PmY9aS.log",
:logfile => "/tmp/mysqld-stdout---supervisor-ZEfmqr.log",
:pid => 14431,
:description => "",
:spawnerr => "",
:stop => 1286783535,
:name => "mysqld",
:statename => "STARTING",
:exitstatus => 0
}
]
]
# Example of using ruby's net/http to send requests to a webserver listening on
# a unix socket. Traditionally this is awkward because most http libraries only
# support TCP sockets. Luckily, the net/http module is written in a modular
# way so we can reuse the HTTP features on our own socket.
require "net/http"
require "socket"
require "rubygems"
require "xml/libxml/xmlrpc" # gem libxml-xmlrpc
require "ap" # gem awesome_print
# Net::HTTP requests internally use Net::BufferedIO, so we must, too.
sock = Net::BufferedIO.new(UNIXSocket.new("/var/run/supervisor.sock"))
# Make a new request, exec it on our unix socket.
request = Net::HTTP::Post.new("/RPC2")
request.content_type = "text/xml"
# See http://supervisord.org/api.html
# Call supervisor.getAllProcessInfo
request.body = XML::XMLRPC::Builder.call("supervisor.getAllProcessInfo")
request.exec(sock, "1.1", "/RPC2")
# Wait for and parse the http response.
begin
response = Net::HTTPResponse.read_new(sock)
end while response.kind_of?(Net::HTTPContinue)
response.reading_body(sock, request.response_body_permitted?) { }
# Parse the XMLRPC response
xml = XML::XMLRPC::Parser.new(response.body)
ap xml.params
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment