1

Question

I want to be able to debug my Sinatra website hosted by Thin on my local machine, and I want to be able to initiate this by using rake.

I'm not able to accept answers suggesting the use of different technologies (e.g. Windows, Rails, Java) or other servers (e.g. unicorn, passenger, puma); however, if what I'm asking for is impossible, then I will accept that answer.

What I've tried

My current Rakefile contains a task :start which starts the Thin server, but when it hits the breakpoint no output is displayed on my terminal. If I start Thin directly from the terminal, then I see the (rdb:1) prompt when it hits the breakpoint as expected. In either case, the Thin server is correctly running the site (confirmed by commenting out the breakpoint).

Gemfile

source :rubygems
gem 'sinatra'
gem 'thin'
gem 'debugger-pry'

Rakefile

task :start do
  conf = File.expand_path('config.ru', File.dirname(__FILE__))
  `thin -e development -R #{conf} --debug start`
end

config.ru

require File.expand_path('app', File.dirname(__FILE__))

run ModularExample::App.new

app.rb

require 'sinatra'
require 'debugger/pry'

module ModularExample
  class App < Sinatra::Base
    get '/' do
      debugger
      "Hello, world"
    end
  end
end
davidzarlengo
  • 820
  • 1
  • 5
  • 16

1 Answers1

3

You're not outputting to STDOUT. The backticks execute the command and return the output as a string so you could do something like

puts `thin -e development -R #{conf} --debug start`

but you want to stream the processes output to STDOUT so you actually want to do:

task :start do
  conf = File.expand_path('config.ru', File.dirname(__FILE__))
  exec("thin -e development -R #{conf} --debug start")
end

Learn more about calling command line calls from this question.

Community
  • 1
  • 1
sunnyrjuneja
  • 6,033
  • 2
  • 32
  • 51