Guest User

Untitled

a guest
May 27th, 2018
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.71 KB | None | 0 0
  1. # request.port is unfortunately useless from within the app, as it
  2. # does not reflect the backend bind port, but the frontend proxy.
  3. # So we have to reverse lookup the PID to figure out our port.
  4. def backend_server_port
  5. Thread.current[:backend_server_port] ||= begin
  6. logger.debug "Attempting to reverse-lookup server port from PID file"
  7. port = nil
  8. Dir["#{RAILS_ROOT}/tmp/pids/thin.*.pid"].each do |f|
  9. pid = File.read(f).chomp.to_i
  10. if pid == $$
  11. port = f.gsub(/.*\.([0-9]+)\.pid$/, '\1').to_i
  12. raise "Malformed PID file does not contain port: #{f}" if port == 0
  13. break
  14. end
  15. end
  16. port || 3000 # guess 3000 for local dev
  17. end
  18. end
Add Comment
Please, Sign In to add comment