I’ve finally figured out how to get Pow and Ruby's debugger working together. It’s actually painfully straight forward and easy to set up. It’s also fully unobstrusive so it’s not going to be in anyone’s way who would be using Passenger or one of the standard Ruby servers like Webrick, Unicorn or Mongrel.
Pow lets you customize the environment in which worker processes run. Before an application boots, Pow attempts to execute two scripts — first
.powrc and then
.powenv — in the application’s root. Any environment variables exported from these scripts are passed along to Rack. So let’s make use of them and add the following into your project’s
After that, ensure that the Ruby debugger is loaded. For Rails apps, it’s pretty straight forward, add debugger into your
group :development do gem 'debugger' end
If you are ready, let’s actually make use of the debugger and run it in remote mode (yes, you can connect to it from a remote process), ensuring that the remote mode is only set if we are running our app within Pow:
# config/environments/development.rb if ENV['ENABLE_REMOTE_DEBUGGER_UNDER_POW'] && Debugger Debugger.settings[:autoeval] = true Debugger.settings[:autolist] = 1 Debugger.settings[:reload_source_on_change] = true Debugger.start_remote end
Make sure to restart your application (
touch tmp/restart.txt). This will activate the debugger and run it in remote mode that will allow us to connect to from outside of the application’s process:
bundle exec rdebug -c
Add a debugger statement to your app and look how the debugger will pick it up, just like if it was a debugger call when running your app through the other application servers.
Simple as that.
I'm a Ruby/JS dev/trainer with a focus on quality. An ex-Londoner, @terracycle, @ubxd, @lastfm. Follow me at http://twitter.com/attilagyorffy