Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using ruby-debug when running rails through foreman #58

Closed
dunkstewart opened this issue Aug 20, 2011 · 13 comments
Closed

Using ruby-debug when running rails through foreman #58

dunkstewart opened this issue Aug 20, 2011 · 13 comments

Comments

@dunkstewart
Copy link

Apologies, if this is a silly question, I may be grasping at straws here considering the more typical use cases for foreman.

I've recently started using foreman to manage the processes in my development environment. I'm happy with the setup, it allows me to run rails, sphinx, and delayed job together and kill them all without forgetting about one of them.

However, putting a "debugger" breakpoint in my ruby code and starting a debug console is a problem with this setup. The breakpoint does get hit because the web request hangs waiting to continue, but there is no interactive debug console on the foreman terminal.

Is it possible to get an interactive debug console while running rails through foreman in development?

I'm running rails 3.0.6, ruby 1.9.2 and foreman 0.19.0

@millisami
Copy link

+10 For the above concern.

More on the commenting the line inside Procfile.
If I just want not to run some process, we all do put #... for that process not to run, but it does run?
What is the proper way of commenting?

@aaronbrethorst
Copy link

I'm trying to understand how to accomplish the same thing as the author. How do you get access to a debug console when you're running your development setup with foreman?

@adahl
Copy link

adahl commented Sep 5, 2011

Same problem as author...

@samdalton
Copy link

I'm also having this issue when using pry's debugging.

@leehambley
Copy link

Is it possible to get an interactive debug console while running rails through foreman in development?

You should look at using remote debuggers… I had some limited success, the notion being that somewhere in an initializer for development mode you set something like the following:

Debugger.wait_connection = true
Debugger.start_remote

There's more documentation here - long story short, the wait_connection = true line should ensure that the debugger pauses for a fixed amount of time (no clue how long) waiting for you to run:

$ rdebug -c

In another terminal, this is how one has to debug when using Passenger, or some other process. I believe that if you skip the wait_remote line, the debug statements are only effective if you previously ran rdebug -c and it is waiting for a server to come up.

YMMV, but I think remote debugging is the way to solve this. Perhaps as an issue, if someone figures it out reliably, they could commit some documentation.

(I also can't say anything about Pry, except that as far as I know it's also only a wrapper around ruby-debug, so the results should be similar.)

@dunkstewart
Copy link
Author

Hi leehambley,

That solution works very well indeed! And is some very handy knowledge to have, thank you.

I didn't need to include the Debugger.wait_connection = true line which may be more useful for short running scripts that would otherwise exit before you connect.

The only other complication I had in my setup was that I'm running guard-spork which is using drb on port 8989 as well. I used Debugger.start_remote(nil, 8991) and rdebug -c -p 8991. You could also change guard-spork to use another port.

Thanks again for this info, this will come in very handy.

@millisami
Copy link

@dunkstewart Can you post a wiki according to your setup so that it would be easy enough for others?

@vinnividivicci
Copy link

@dunkstewart I removed the Debugger.wait_connection = true as well since it was causing issues with nginx. Now I can connect to any of my load balanced instances with the debugger. Thanks guys! @leehambley

@shioyama
Copy link

For anyone wanting to use pry in foreman, pry-remote seems to do the trick for me.

@jaredbeck
Copy link

For anyone wanting to use pry in foreman, pry-remote seems to do the trick for me.

Two years later, byebug also has support for remote debugging. Use Byebug.start_server and byebug -R. See also Nicholas Gronow's example on SO: https://stackoverflow.com/a/25823241/567762

@ndbroadbent
Copy link
Contributor

If anyone else reads this issue, tmuxinator is a great alternative that also allows you to start multiple processes. It runs them in different tmux "panes" instead of grouping all of the output, so you are able to use a debugger. Foreman is awesome, but I would highly recommend tmuxinator for development.

@erezny
Copy link

erezny commented Jun 10, 2019

If you'd like to run whatever's in your procfile as if you had pasted it into your terminal you can use run rather than start and then your interactive apps will work fine. You just can't run more than one app in one terminal.

Procfile

web: bundle exec rails s
$ foreman run web

@nijeesh-rently
Copy link

I have been trying out overmind and it great so far.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests