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