如何调试由工头开始的rails(3.2)应用程序? [英] How to debug a rails (3.2) app started by foreman?
问题描述
我正试图用工头来启动我的rails应用程序。不幸的是,连接我的IDE进行调试时遇到困难。
我阅读了此处使用
Debugger.wait_connection = true
pre>
Debugger.start_remote
启动远程调试会话,但这并没有真正解决。
问题:
有没有办法调试由工头开始的rails(3.2)应用程序?如果是这样,那么这个方法是什么?解决方案如果你使用几个具有完整的rails环境的工作人员,可以使用下面的初始化器: / p>
#启用与工头的调试器,请参阅https://github.com/ddollar/foreman/issues/58
if Rails.env.development?
require'debugger'
Debugger.wait_connection = true
def find_available_port
server = TCPServer.new(nil,0)
server.addr [1 ]
确保
server.close如果服务器
结束
port = find_available_port
将远程调试器在端口#{port}
Debugger.start_remote(nil,port)
end
在工头的日志中,你会可以找到调试器的端口:
$ foreman start
12:48:42 web.1 |以pid 29916开始
12:48:42 worker.1 |以pid 29921开始
12:48:44 web.1 | I,[2012-10-30T12:48:44.810464#29916] INFO - :listen on addr = 0.0.0.0:5000 fd = 10
12:48:44 web.1 |我,[2012-10-30T12:48:44.810636#29916] INFO - :刷新宝石列表
12:48:47 web.1 |端口59269上的远程调试器
12:48:48 worker.1 |端口41301上的远程调试器
现在运行调试器:
rdebug -c -p [PORT]
I am trying to use foreman to start my rails app. Unfortunately I have difficulties connecting my IDE for debugging.
I read here about using
Debugger.wait_connection = true Debugger.start_remote
to start a remote debugging session, but that does not really work out.
Question: Is there a way to debug a rails (3.2) app started by foreman? If so, what is the approach?
解决方案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/58 if 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 start 12:48:42 web.1 | started with pid 29916 12:48:42 worker.1 | started with pid 29921 12:48:44 web.1 | I, [2012-10-30T12:48:44.810464 #29916] INFO -- : listening on addr=0.0.0.0:5000 fd=10 12:48:44 web.1 | I, [2012-10-30T12:48:44.810636 #29916] INFO -- : Refreshing Gem list 12:48:47 web.1 | Remote debugger on port 59269 12:48:48 worker.1 | Remote debugger on port 41301
Now run debugger using:
rdebug -c -p [PORT]
这篇关于如何调试由工头开始的rails(3.2)应用程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!