Capistrano の変数を Unicorn サーバの設定で利用する


Capistarano で環境変数を設定しconfig/unicorn.rbで参照すればいい

config/deploy.rb
set :user, do # ユーザ名を入力させる
  Capistrano::CLI.ui.ask("User: ") 
end
set :application, "ikemen"
default_environment['DEPLOY_USER'] = user
default_environment['DEPLOY_APP_NAME'] = application
config/unicorn.rb
user = ENV['DEPLOY_USER'] || 'username' # ENV['USER'] でも取れたりする...
application = ENV['DEPLOY_APP_NAME'] || 'busaiku'

root_path = "/var/www/users/#{user}/#{application}"
listen "/tmp/#{user}_#{application}_unicorn.sock"

stderr_path "#{root_path}/shared/log/unicorn.log"
stdout_path "#{root_path}/shared/log/unicorn.log"

worker_processes 2
pid "#{root_path}/shared/pids/unicorn.pid"
working_directory "#{root_path}/current"

こんな感じでサーバ側に値を渡してやる