rvm で unicorn
疑問
例えば起動スクリプト経由で rvm の任意の gemset を利用して unicorn を起動するにはどうすれば良いのか。
回答
普通に公式に答えがあった。 rvm コマンドで wrapper を作れば良いらしい。
例えば "1.9.2@rails3000" という gemset で unicorn を start する wrapper を作るには、
$ rvm wrapper 1.9.2@rails3000 start unicorn
というコマンドを実行すれば、
$ ll ~/.rvm/bin
lrwxrwxr-x 1 yuanying staff 62 10 12 16:47 start_unicorn@ -> /Users/yuanying/.rvm/wrappers/ruby-1.9.2@rails300/unicorn
~/.rvm/bin 以下に start_unicorn というスクリプトが生成される。 そのまま普通のコマンドのように実行すればよろしい。
$ ~/.rvn/bin/start_unicorn --help
Usage: unicorn [ruby options] [unicorn options] [rackup config file]
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
unicorn options:
-o, --host HOST listen on HOST (default: 0.0.0.0)
-p, --port PORT use PORT (default: 8080)
-E, --env ENVIRONMENT use ENVIRONMENT for defaults (default: development)
-D, --daemonize run daemonized in the background
-s, --server SERVER this flag only exists for compatibility
-l {HOST:PORT|PATH}, listen on HOST:PORT or PATH
--listen this may be specified multiple times
(default: 0.0.0.0:8080)
-c, --config-file FILE Unicorn-specific config file
Common options:
-h, --help Show this message
-v, --version Show version
中身はこんな感じ。
#!/usr/bin/env sh
if [ -s "/Users/yuanying/.rvm/environments/ruby-1.9.2-head@rails300" ] ; then
. "/Users/yuanying/.rvm/environments/ruby-1.9.2-head@rails300"
exec unicorn "$@"
else
echo "ERROR: Missing RVM environment file: '/Users/yuanying/.rvm/environments/ruby-1.9.2-head@rails300'"
exit 1
fi
ということで、普通に thin やら mongrel も wrapper 経由で起動する事ができる模様。
$ rvm wrapper 1.9.2@rails3000 start thin
とか、
$ rvm wrapper 1.9.2@rails3000 start mongrel
って感じかね。
てか、mongrel ってまだ使ってる人いるのか知らん。