How to debug a rails (3.2) app started by foreman? How to debug a rails (3.2) app started by foreman? ruby-on-rails ruby-on-rails

How to debug a rails (3.2) app started by foreman?


If you use several workers with full rails environment you could use the following initializer:

# Enabled debugger with foreman, see https://github.com/ddollar/foreman/issues/58if Rails.env.development?  require 'debugger'  Debugger.wait_connection = true  def find_available_port    server = TCPServer.new(nil, 0)    server.addr[1]  ensure    server.close if server  end  port = find_available_port  puts "Remote debugger on port #{port}"  Debugger.start_remote(nil, port)end

And in the foreman's logs you'll be able to find debugger's ports:

$ foreman start12:48:42 web.1     | started with pid 2991612:48:42 worker.1  | started with pid 2992112:48:44 web.1     | I, [2012-10-30T12:48:44.810464 #29916]  INFO -- : listening on addr=0.0.0.0:5000 fd=1012:48:44 web.1     | I, [2012-10-30T12:48:44.810636 #29916]  INFO -- : Refreshing Gem list12:48:47 web.1     | Remote debugger on port 5926912:48:48 worker.1  | Remote debugger on port 41301

Now run debugger using:

rdebug -c -p [PORT]


One approach is to require debugger normally in your gemfile, and add debugger normally in your code as needed. When the server hits that line, it will stop, but foreman won't be verbose about it. In your foreman console you can blindly type irb, and only then will you see a prompt appear. Bad UX, right?

Another (augmentative) approach is to tail your logs:

tail -f log/development.log

Hope this helps.