Skip to content

Commit

Permalink
Allow an environment to be given to unicorn, based on rails' config
Browse files Browse the repository at this point in the history
  • Loading branch information
lemoinem committed Nov 9, 2012
1 parent 5eefe22 commit fbfb990
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
4 changes: 4 additions & 0 deletions README.txt
Expand Up @@ -59,6 +59,10 @@ unicorn_rackup:: The location of the rackup file unicorn should load.
unicorn_use_sudo:: Whether to use sudo to run the 'unicorn' command on
the remote host. Probably necessary if you specify a
user and group in unicorn.rb.
unicorn_env:: Environment to be given to unicorn (value for `-E`).
Default value is based on `vlad/rails`'s `rails_env`.
If `rails_env` is not defined, `production` is used as
default value.

For more on specific issues when deploying Rails applications, see
rails-configuration.txt[link:docs/rails-configuration_txt.html].
Expand Down
5 changes: 3 additions & 2 deletions lib/vlad/unicorn_common.rb
Expand Up @@ -19,13 +19,13 @@ def self.signal(sig = '0')

def self.start(opts = '')
cmd = signal('HUP')
cmd << %( || (#{unicorn_command} -D --config-file #{unicorn_config} #{opts}))
cmd << %( || (#{unicorn_command} -D -E "#{unicorn_env}" --config-file #{unicorn_config} #{opts}))
maybe_sudo %(sh -c '#{cmd}')
end

def self.reload(opts = '')
cmd = signal('USR2')
cmd << %( || (#{unicorn_command} -D --config-file #{unicorn_config} #{opts}))
cmd << %( || (#{unicorn_command} -D -E "#{unicorn_env}" --config-file #{unicorn_config} #{opts}))
maybe_sudo %(sh -c '#{cmd}')
end

Expand All @@ -42,6 +42,7 @@ def self.stop
set(:unicorn_config) { "#{current_path}/config/unicorn.rb" }
set :unicorn_use_sudo, false
set(:unicorn_pid) { "#{shared_path}/pids/unicorn.pid" }
set(:unicorn_env) { begin rails_env ; rescue Rake::FetchError => e ; "production" end }

desc "Stop the app servers"
remote_task :stop_app, :roles => :app do
Expand Down

0 comments on commit fbfb990

Please sign in to comment.