Created
March 30, 2011 14:35
-
-
Save jamiew/894509 to your computer and use it in GitHub Desktop.
rails2.3 config.ru using rack_proctitle -- kept in lib/rack_proctitle.rb and loaded in config/environment.rb
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ENV['RAILS_ENV'] = ENV['RACK_ENV'] | |
require "config/environment" | |
use Rails::Rack::LogTailer | |
use Rails::Rack::Static | |
use Rack::ProcTitle | |
run ActionController::Dispatcher.new |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Rack | |
# Middleware to update the process title ($0) with information about the | |
# current request. Based loosely on: | |
# - http://purefiction.net/mongrel_proctitle/ | |
# - http://github.com/grempe/thin-proctitle/tree/master | |
# | |
# NOTE: This will not work properly in a multi-threaded environment. | |
class ProcTitle | |
F = ::File | |
PROGNAME = F.basename($0) | |
def initialize(app) | |
@app = app | |
@appname = Dir.pwd.split('/').reverse. | |
find { |name| name !~ /^(\d+|current|releases)$/ } || PROGNAME | |
@requests = 0 | |
$0 = "#{PROGNAME} [#{@appname}] init ..." | |
end | |
def call(env) | |
host, port = env['SERVER_NAME'], env['SERVER_PORT'] | |
meth, path = env['REQUEST_METHOD'], env['PATH_INFO'] | |
@requests += 1 | |
$0 = "#{PROGNAME} [#{@appname}/#{port}] (#{@requests}) #{meth} #{path}" | |
@app.call(env) | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment