[ANN] Mongrel Console 0.1 -- script/console meets mongrel

This is a super quick announcement for a new Mongrel plugin called
mongrel_console. It was inspired by a request from Tobias Lütke who wanted
to tail out logs while Mongrel was running.

What mongrel_console does is combine the Rails script/console with
Mongrel
so that you can control a mongrel server while using script/console.
Sounds
weird but it’s quite awesome for development hacking. You get to start,
stop, and reload mongrel and rails while also munging with your AR
models
and running other Rails code.

INSTALL

You can install it via:

gem install mongrel_console
–source=http://mongrel.rubyforge.org/releases/

Then you run it with:

$ cd myrailsapp
$ mongrel_rails console

USAGE

You then get an IRB prompt but that you can use like script/console.
But,
now there’s a bunch of new commands you can use to control Mongrel:

  • start – Starts up a Mongrel instance and runs your Rails app in the
    background. Accepts an option hash. See status to find out what’s
    available.
  • stop – Stops the currently running Mongrel instance.
  • restart – Stops then starts using your previous options. If you want
    to
    change options then manually start and stop with new options.
  • status – Tells you if Mongrel is running and then dumps the options
    Hash.
  • trace – Tells Mongrel to dump all of the request and response headers
    to
    log/mongrel.log. Incredibly useful if you think Mongrel is broken for
    some
    reason or if you suspect you’ve got a bad header some place.
  • tail – Let’s you tail a file out (doesn’t go back to the prompt). By
    default it tails the log for your environment (log/development.log).
    Very
    useful with trace (try tail “log/mongrel.log”).

EXAMPLE

Here’s me using it during development:

Loading development environment.
Starting console. Mongrel Commands: start, stop, reload, restart,
status,
trace, tail
irb(main):001:0> start
Mongrel running in development mode on 0.0.0.0:3000.
=> nil
irb(main):002:0> trace
Tracing mongrel requests and responses to log/mongrel.log
=> nil
irb(main):003:0> tail “log/mongrel.log”
Tailing log/mongrel.log. CTRL-C to stop it.

^C=> nil
irb(main):004:0> reload
Reloading rails…
Done reloading rails.
=> nil
irb(main):005:0> restart
Server stopped. Exiting.
Shutdown waiting for 20 requests
Mongrel running in development mode on 0.0.0.0:3000.
=> nil
irb(main):006:0> status
Mongrel running with:

  • mime:
  • docroot: public
  • server: #Mongrel::HttpServer:0x253441c
  • tracing: true
  • rails: #RailsHandler:0x25344d0
  • host: 0.0.0.0
  • port: 3000
    => nil
    irb(main):007:0> stop
    Server stopped. Exiting.
    Shutdown waiting for 20 requests
    => nil
    irb(main):008:0> status
    Mongrel not running.
    => nil
    irb(main):009:0> start :port => 4000
    Mongrel running in development mode on 0.0.0.0:4000.
    => nil
    irb(main):010:0> status
    Mongrel running with:
  • mime:
  • docroot: public
  • server: #Mongrel::HttpServer:0x26d4fb0
  • tracing: true
  • rails: #RailsHandler:0x26d5154
  • host: 0.0.0.0
  • port: 4000
    => nil

Win32 people might find the tail command doesn’t work.

Enjoy! Let me know what you think.

Zed A. Shaw

Awesome! I love “reload”. No need to CTRL-C; ; ;
anymore

A couple of little weird bugs people should know about:

  1. I made a mistake in the tracing, so uninstall and then reinstall the
    mongrel_console gem to get a fix.
  2. When you run it with the console going it is very sloooowwwwwww.
    For
    some weird reason you just need to tail a log and it speeds back up.

Have fun.

Zed A. Shaw

Hey Zed –

root# mongrel_rails console
Cannot run the console script: uninitialized constant RailsConfigurator

Any idea on that error msg?

Thanks

Adam R. wrote:

Hey Zed –

root# mongrel_rails console
Cannot run the console script: uninitialized constant RailsConfigurator

Any idea on that error msg?

Thanks

It would be nice for mongrel to have the tailing behavior like
script/server does when you run it in non daemon mode. This mongrel
console is nice though.