2006年04月02日
■ [Mongrel]MongrelでRailsアプリを動かしてみる。 
HSJ.jpでもとりあげたMongrelですが、Win32環境でも動く(しかもWindowsサービスとして)そうなので、ちょっと入れてみることにしました。
インストール
まずはRubyGemsからゲットしてみることにします。アーカイブは一応RubyForgeにもあります。
C:\Rails>gem install mongrel
Attempting local installation of 'mongrel'
Local gem file not found: mongrel*.gem
Attempting remote installation of 'mongrel'
Updating Gem source index for: http://gems.rubyforge.org
Select which gem to install for your platform (i386-mswin32)
1. mongrel 0.3.12 (ruby)
2. mongrel 0.3.12 (mswin32)
3. mongrel 0.3.11 (mswin32)
4. mongrel 0.3.11 (ruby)
...中略...
24. mongrel 0.2.1 (ruby)
25. mongrel 0.2.0 (ruby)
26. Cancel installation
> 2
Install required dependency win32-service? [Yn] y
Select which gem to install for your platform (i386-mswin32)
1. win32-service 0.5.0 (mswin32)
2. Cancel installation
> 1
ERROR: While executing gem ... (RuntimeError)
win32-service requires Ruby version >= 1.8.3
C:\Rails>
あれっ(笑)
そうなんですね、今入れてるActiveScriptRubyは1.8.2.6なんですよねぇ…。
ま、仕方ないか。とりあえずruby版を...
C:\Rails>gem install mongrel
Attempting local installation of 'mongrel'
Local gem file not found: mongrel*.gem
Attempting remote installation of 'mongrel'
Select which gem to install for your platform (i386-mswin32)
1. mongrel 0.3.12 (ruby)
2. mongrel 0.3.12 (mswin32)
3. mongrel 0.3.11 (mswin32)
...中略...
24. mongrel 0.2.1 (ruby)
25. mongrel 0.2.0 (ruby)
26. Cancel installation
> 1
Install required dependency daemons? [Yn] y
Install required dependency gem_plugin? [Yn] y
ERROR: While executing gem ... (RuntimeError)
mongrel requires Ruby version >= 1.8.4
C:\Rails>
ってことで、ActiveScriptRuby 1.8.4.1をまず入れます。(先に1.8.2をアンインストールします)
その後、もう一度gemコマンドを実行します。
C:\Rails>gem install mongrel
...中略...
Select which gem to install for your platform (i386-mswin32)
1. mongrel 0.3.12 (ruby)
2. mongrel 0.3.12 (mswin32)
...中略...
26. Cancel installation
> 2
Install required dependency win32-service? [Yn] y
Select which gem to install for your platform (i386-mswin32)
1. win32-service 0.5.0 (mswin32)
2. Cancel installation
> 1
Successfully installed mongrel-0.3.12-mswin32
Successfully installed win32-service-0.5.0-mswin32
Installing RDoc documentation for mongrel-0.3.12-mswin32...
lib/mongrel/rails.rb:135:49: Skipping require of dynamic string: "#{ops[:cwd]}/c
onfig/environment"
Installing RDoc documentation for win32-service-0.5.0-mswin32...
C:\Rails>
ということでアッサリ通過。
使い方
Mongrelのサイトに書いてあるとおりこんな感じに実行する。
開始
C:\Rails>cd app_name C:\Rails\app_name>mongrel_rails start -d
さっくり動きます。
終了
C:\Rails\app_name>mongrel_rails stop
と思ったけど、Win32環境だとだめっぽ。
CTRL-Pause/Breakで終わらせましょう。
startオプションを確認する
C:\Rails>mongrel_rails start -h
Usage: mongrel_rails [options]
-e, --environment ENV Rails environment to run as
-d, --daemonize Whether to run in the background or not
-p, --port PORT Which port to bind to
-a, --address ADDR Address to bind to
-l, --log FILE Where to write log messages
-P, --pid FILE Where to write the PID
-n, --num-procs INT Number of processor threads to use
-t, --timeout SECONDS Timeout all requests after SECONDS time
-m, --mime PATH A YAML file that lists additional MIME typ
s
-c, --chdir PATH Change to dir before starting (will be exp
nded)
-r, --root PATH Set the document root (default 'public')
-B, --debug Enable debugging mode
-C, --config PATH Use a config file
-h, --help Show this message
--version Show version
C:\Rails>
Windowsサービスの使い方
C:\Rails>mongrel_rails_service install -n new_service_name -r c:C:\Rails\app_name -p 4000 -e production C:\Rails>mongrel_rails_service start -n new_service_name C:\Rails>mongrel_rails_service stop -n new_service_name
オプション
C:\Rails>mongrel_rails_service install -h
Usage: mongrel_rails_service [options]
-n, --name SVC_NAME Required name for the service to be registered/installed.
-d, --display SVC_DISPLAY Adjust the display name of the service.
-r, --root PATH Set the root path where your rails app resides.
-e, --environment ENV Rails environment to run as. (default: production)
-b, --binding ADDR Address to bind to
-p, --port PORT Which port to bind to
-m, --mime PATH A YAML file that lists additional MIME types
-P, --num-procs INT Number of processor threads to use
-t, --timeout SECONDS Timeout all requests after SECONDS time
-c, --cpu CPU Bind the process to specific cpu, startingfrom 1.
-h, --help Show this message
--version Show version
C:\Rails>mongrel_rails_service delete -h
Usage: mongrel_rails_service [options]
-n, --name SVC_NAME Required name for the service to be registered/installed.
-h, --help Show this message
--version Show version
C:\Rails>mongrel_rails_service start -h
Usage: mongrel_rails_service [options]
-n, --name SVC_NAME Required name for the service to be registered/installed.
-h, --help Show this message
--version Show version
C:\Rails>mongrel_rails_service stop -h
Usage: mongrel_rails_service [options]
-n, --name SVC_NAME Required name for the service to be registered/installed.
-h, --help Show this message
--version Show version
%uの解釈について
該当部分を見てみると、やっぱり考慮されていないですね。
module Mongrel
class HttpRequest
def self.escape(s)
s.to_s.gsub(/([^ a-zA-Z0-9_.-]+)/n) {
'%'+$1.unpack('H2'*$1.size).join('%').upcase
}.tr(' ', '+')
end
def self.unescape(s)
s.tr('+', ' ').gsub(/((?:%[0-9a-fA-F]{2})+)/n){
[$1.delete('%')].pack('H*')
}
end
end
end
どうやって修正したものやら。
コメント