Pinto公開に向けて #14 ― rackupの「-E」オプション
あらすじ
Pintoというソーシャルブックマークサービスを、Rubyで開発中です(GitHubリポジトリ)。開発中に気づいたことや工夫した点などを、備忘録も兼ねて書いています。その14回目です。
本題
Rack本体のbin/rackupにはいろいろなオプションを渡せます。
>rackup --help Usage: rackup [ruby options] [rack options] [rackup config] Ruby options: -e, --eval LINE evaluate a LINE of code -d, --debug set debugging flags (set $DEBUG to true) -w, --warn turn warnings on for your script -I, --include PATH specify $LOAD_PATH (may be used more than once) -r, --require LIBRARY require the library, before executing your script Rack options: -s, --server SERVER serve using SERVER (webrick/mongrel) -o, --host HOST listen on HOST (default: 0.0.0.0) -p, --port PORT use PORT (default: 9292) -E, --env ENVIRONMENT use ENVIRONMENT for defaults (default: development) Common options: -h, --help Show this message --version Show version
この「-E」(または「--env」)オプションに関する話です。
ご覧のとおり、デフォルトが「development」になっていますね。これは、bin/rackupの中で下記のように使われます。
case env when "development" app = Rack::Builder.new { use Rack::CommonLogger, STDERR unless server.name =~ /CGI/ use Rack::ShowExceptions use Rack::Reloader use Rack::Lint run inner_app }.to_app when "deployment" app = Rack::Builder.new { use Rack::CommonLogger, STDERR unless server.name =~ /CGI/ run inner_app }.to_app when "none" app = inner_app end
デフォルトのままだと、Rack::CommonLogger や Rack::ShowExceptions などが知らぬまにuseされてしまうわけです。私にとっては、微妙にありがた迷惑なんですよね。この辺りはアプリ側で制御するのが適切なのではないかと思います。
というわけで、起動コマンドでは「-E none」とすることに決めました。
rackup -s mongrel -p 80 -E none script/server.ru
developmentなのかdeploymentなのか、Pinto側で制御する方法を検討しなければなりませんが、それはまた次回以降に。