From 1054d58e9065a6773542888cb238d9f3ff36cd5a Mon Sep 17 00:00:00 2001 From: Yury Velikanau Date: Mon, 14 Jul 2014 13:03:01 -0700 Subject: [PATCH 1/2] Customize unicorn command. Lets you customize unicorn command to something other than `bundle exec unicorn`, for example `bin/unicorn`. Also includes minor updates such as using `current_path.join` instead of `File.join`. --- lib/capistrano3/tasks/unicorn.rake | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/lib/capistrano3/tasks/unicorn.rake b/lib/capistrano3/tasks/unicorn.rake index 8003528..9f6d41f 100644 --- a/lib/capistrano3/tasks/unicorn.rake +++ b/lib/capistrano3/tasks/unicorn.rake @@ -1,11 +1,13 @@ namespace :load do task :defaults do - set :unicorn_pid, -> { File.join(current_path, "tmp", "pids", "unicorn.pid") } + set :unicorn_command, 'bundle exec unicorn' + set :unicorn_pid, -> { current_path.join('tmp', 'pids', 'unicorn.pid') } set :unicorn_config_path, -> do - if File.exist?(File.join(current_path, "config", "unicorn", "#{fetch(:rails_env)}.rb")) - File.join(current_path, "config", "unicorn", "#{fetch(:rails_env)}.rb") + unicorn_env_path = current_path.join('config', 'unicorn', "#{fetch(:rails_env)}.rb") + if File.exist?(unicorn_env_path) + unicorn_env_path else - File.join(current_path, "config", "unicorn.rb") + current_path.join('config', 'unicorn', "unicorn.rb") end end set :unicorn_roles, -> { :app } @@ -24,7 +26,7 @@ namespace :unicorn do info "unicorn is running..." else with rails_env: fetch(:rails_env) do - execute :bundle, "exec unicorn", "-c", fetch(:unicorn_config_path), "-E", fetch(:unicorn_rack_env), "-D", fetch(:unicorn_options) + execute fetch(:unicorn_command), '-c', fetch(:unicorn_config_path), '-E', fetch(:unicorn_rack_env), '-D', fetch(:unicorn_options) end end end From e3153244e32ac883ab1562c6a4370b82fe0fccd3 Mon Sep 17 00:00:00 2001 From: Yury Velikanau Date: Mon, 14 Jul 2014 14:55:33 -0700 Subject: [PATCH 2/2] Better backward compatibility. According to https://github.com/capistrano/capistrano#tasks, commands with spaces gets executed slightly differently. To preserve 'better' behaviour, use splat operator for the first argument to `execute` and make default contain array of command chunks. It is perfectly fine to set `unicorn_command` to just 'bin/unicorn', splat can handle that. --- lib/capistrano3/tasks/unicorn.rake | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/capistrano3/tasks/unicorn.rake b/lib/capistrano3/tasks/unicorn.rake index 9f6d41f..25d0823 100644 --- a/lib/capistrano3/tasks/unicorn.rake +++ b/lib/capistrano3/tasks/unicorn.rake @@ -1,6 +1,6 @@ namespace :load do task :defaults do - set :unicorn_command, 'bundle exec unicorn' + set :unicorn_command, -> { [:bundle, :exec, :unicorn] } set :unicorn_pid, -> { current_path.join('tmp', 'pids', 'unicorn.pid') } set :unicorn_config_path, -> do unicorn_env_path = current_path.join('config', 'unicorn', "#{fetch(:rails_env)}.rb") @@ -26,7 +26,7 @@ namespace :unicorn do info "unicorn is running..." else with rails_env: fetch(:rails_env) do - execute fetch(:unicorn_command), '-c', fetch(:unicorn_config_path), '-E', fetch(:unicorn_rack_env), '-D', fetch(:unicorn_options) + execute *fetch(:unicorn_command), '-c', fetch(:unicorn_config_path), '-E', fetch(:unicorn_rack_env), '-D', fetch(:unicorn_options) end end end