ruby-on-railsdebuggingthinshotgun

Set up shotgun to start thin with its debug flag


I am trying to get the debugger gem working with shotgun, and for the debugger to work I need the thin server to be started with "Debugging ON".

If I run either:

shotgun -p 1378 -s thin -d -o 0.0.0.0
shotgun -p 1378 -s thin --debug -o 0.0.0.0

I get shotgun starting with the $DEBUG ruby variable being set to true, instead of having the thin server being started with the debug flag on.

If I run:

shotgun -pp 1378 -s "thin --debug" -o 0.0.0.0

I get an error. Is there another way to run this, or some way to tell thin to start in debugger mode when the environment is set to development?


Solution

  • Your -d and --debug options are being interpreted by Shotgun, rather than Thin, and that is what is setting $DEBUG to true.

    Thin’s command line flag to turn on debugging is -D or --debug and this sets Thin::Logging.debug to true. You can’t use the thin command line options (sine the command line is being read by shotgun which launches the server), but you can set this variable with some normal Ruby code. One way to do this would be with a shotgun.rb file that requires Thin and changes the setting:

    require 'thin'
    Thin::Logging.debug = true
    

    (You might want to put this in a begin...rescue...block and rescue the LoadError in case Thin isn’t available.)

    The output without this file:

    $ shotgun
    == Shotgun/Thin on http://127.0.0.1:9393/
    >> Thin web server (v1.4.1 codename Chromeo)
    >> Maximum connections set to 1024
    >> Listening on 127.0.0.1:9393, CTRL+C to stop
    

    and with the file:

    $ shotgun
    == Shotgun/Thin on http://127.0.0.1:9393/
    >> Thin web server (v1.4.1 codename Chromeo)
    >> Debugging ON
    >> Maximum connections set to 1024
    >> Listening on 127.0.0.1:9393, CTRL+C to stop
    

    As far as I can tell, this setting only affects the verbosity of Thin’s logging, and doesn’t have anything to do with the Debugger gem.