Created
March 10, 2014 21:33
-
-
Save mitio/9474838 to your computer and use it in GitHub Desktop.
A quick script to call a Phusion Passenger process directly to assist in debugging server issues.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
status = `passenger-status -v --show=xml` | |
pid_to_show = ARGV.first | |
processes = {} | |
def extract(tag_name, xml) | |
if xml =~ /<#{tag_name}>(.*?)<\/#{tag_name}>/s | |
$1.to_s.strip | |
else | |
'' | |
end | |
end | |
def extract_all(tag_name, xml) | |
xml.scan(/<#{tag_name}>(.*?)<\/#{tag_name}>/s) do |(tag_content,)| | |
yield tag_content | |
end | |
end | |
extract_all 'process', status.to_s do |process| | |
pid = extract 'pid', process | |
pass = extract 'connect_password', process | |
http = nil | |
extract_all 'server_socket', extract('server_sockets', process) do |socket| | |
name = extract 'name', socket | |
http = extract 'address', socket if name == 'http' | |
end | |
processes[pid] = {:pass => pass, :address => http} | |
end | |
while pid_to_show.nil? | |
puts "Select a PID to send the request to:" | |
processes.each do |pid, process| | |
puts "#{pid} at #{process[:address]}" | |
end | |
pid = gets.strip | |
if processes.key?(pid) | |
pid_to_show = pid | |
break | |
end | |
end | |
process = processes[pid_to_show] | |
command = "curl -H 'X-Passenger-Connect-Password: #{process[:pass]}' '#{process[:address]}'" | |
system command | |
puts "\n\nRequested PID #{pid_to_show} by HTTP with #{command}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment