capistrano-unicornでハマった話

productionで

Mongoid::Errors::NoSessionConfig (
Problem:
  No configuration could be found for a session named 'default'.
Summary:
  When attempting to create the new session, Mongoid could not find a session configuration for the name: 'default'. This is necessary in order to know the host, port, and options needed to connect.
Resolution:
  Double check your mongoid.yml to make sure under the sessions key that a configuration exists for 'default'. If you have set the configuration programatically, ensure that 'default' exists in the configuration hash.):

こんなエラーがでて

  Double check your mongoid.yml to make sure under the sessions key that a configuration exists for 'default'. If you have set the configuration programatically, ensure that 'default' exists in the configuration hash.):

というのでmongoid.ymlが間違ってないか色々見てたけど解決せず。

たまたまunicornのプロセスみてたら

 6143 ?        Sl     0:01 unicorn_rails master --path /dashboard -c /home/kanetann/dashboard/current/config/unicorn.rb -E deployment -D

あれ?-E deployment?productionじゃなくて?

cap production unicorn:show_vars

# Environments
rails_env          "production"
unicorn_env        "production"
unicorn_rack_env   "deployment"

unicorn_rack_env?

sosedoff/capistrano-unicorn https://github.com/sosedoff/capistrano-unicorn

Environment parameters

unicorn_env - Set basename of unicorn config .rb file to be used loaded from unicorn_config_path.
Defaults to rails_env variable if set, otherwise production.

unicorn_rack_env - Set the value which will be passed to unicorn via the -E parameter as the Rack environment.
Valid values are development, deployment, and none. Defaults to development if rails_env is development, otherwise deployment.

unicorn_rack_envが追加されて-Eはそれを使うようになったと

cat config/deploy/production.rb

set :domain,           "foo.example.com"
set :rails_env,        "production"
set :unicorn_env,      "production"
set :unicorn_rack_env, "production" # とりあえず追記してみる
set :app_env,          "production"

role :web, domain
role :app, domain
role :db,  domain, :primary => true

set :deploy_to,   "/home/#{user}/#{application}/"
set :current_path, File.join(deploy_to, current_dir)

これで動いたけど、Valid values are development, deployment, and none. なんだよなあ。。