From 1c34fd7997652e345aaaa3336ba4d8c710e9555f Mon Sep 17 00:00:00 2001 From: Stafford Brunk Date: Wed, 30 Sep 2015 15:58:25 -0400 Subject: [PATCH 1/4] Remove extraneous pty arg in capistrano2 task --- lib/capistrano/tasks/capistrano2.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/capistrano/tasks/capistrano2.rb b/lib/capistrano/tasks/capistrano2.rb index 5ccfc9e..4d57dde 100644 --- a/lib/capistrano/tasks/capistrano2.rb +++ b/lib/capistrano/tasks/capistrano2.rb @@ -95,7 +95,7 @@ def start_process(pid_file, idx, sidekiq_role) args.push '--daemon' end - run_as "if [ -d #{current_path} ] && [ ! -f #{pid_file} ] || ! kill -0 `cat #{pid_file}` > /dev/null 2>&1; then cd #{current_path} ; #{fetch(:sidekiq_cmd)} #{args.compact.join(' ')} ; else echo 'Sidekiq is already running'; fi", pty: false + run_as "if [ -d #{current_path} ] && [ ! -f #{pid_file} ] || ! kill -0 `cat #{pid_file}` > /dev/null 2>&1; then cd #{current_path} ; #{fetch(:sidekiq_cmd)} #{args.compact.join(' ')} ; else echo 'Sidekiq is already running'; fi" end desc 'Quiet sidekiq (stop accepting new work)' From 418c78e20c0f818a3a282cd4e21995613c518d24 Mon Sep 17 00:00:00 2001 From: Stafford Brunk Date: Wed, 30 Sep 2015 17:30:43 -0400 Subject: [PATCH 2/4] Use sidekiq_user instead of puma_user in the cap3 task --- lib/capistrano/tasks/sidekiq.rake | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/capistrano/tasks/sidekiq.rake b/lib/capistrano/tasks/sidekiq.rake index 97f4699..62610ec 100644 --- a/lib/capistrano/tasks/sidekiq.rake +++ b/lib/capistrano/tasks/sidekiq.rake @@ -216,7 +216,7 @@ namespace :sidekiq do end def switch_user(&block) - su_user = fetch(:puma_user) + su_user = fetch(:sidekiq_user) if su_user as su_user do yield From d8026414c8bf671ad8f600fb8fc91c0f8912185c Mon Sep 17 00:00:00 2001 From: Stafford Brunk Date: Wed, 30 Sep 2015 17:31:05 -0400 Subject: [PATCH 3/4] Add default sidekiq_user value + documentation --- README.md | 1 + lib/capistrano/tasks/capistrano2.rb | 2 ++ lib/capistrano/tasks/sidekiq.rake | 1 + 3 files changed, 4 insertions(+) diff --git a/README.md b/README.md index 6420a3c..e0892b0 100644 --- a/README.md +++ b/README.md @@ -50,6 +50,7 @@ Configurable options, shown here with defaults: :sidekiq_monit_use_sudo => true :sidekiq_cmd => "#{fetch(:bundle_cmd, "bundle")} exec sidekiq" # Only for capistrano2.5 :sidekiqctl_cmd => "#{fetch(:bundle_cmd, "bundle")} exec sidekiqctl" # Only for capistrano2.5 + :sidekiq_user => nil #user to run sidekiq as ``` There is a known bug that prevents sidekiq from starting when pty is true on Capistrano 3. diff --git a/lib/capistrano/tasks/capistrano2.rb b/lib/capistrano/tasks/capistrano2.rb index 4d57dde..6888f07 100644 --- a/lib/capistrano/tasks/capistrano2.rb +++ b/lib/capistrano/tasks/capistrano2.rb @@ -21,6 +21,8 @@ _cset(:sidekiq_processes) { 1 } _cset(:sidekiq_options_per_process) { nil } + _cset(:sidekiq_user) { nil } + if fetch(:sidekiq_default_hooks) before 'deploy:update_code', 'sidekiq:quiet' after 'deploy:stop', 'sidekiq:stop' diff --git a/lib/capistrano/tasks/sidekiq.rake b/lib/capistrano/tasks/sidekiq.rake index 62610ec..45c1657 100644 --- a/lib/capistrano/tasks/sidekiq.rake +++ b/lib/capistrano/tasks/sidekiq.rake @@ -9,6 +9,7 @@ namespace :load do set :sidekiq_role, -> { :app } set :sidekiq_processes, -> { 1 } set :sidekiq_options_per_process, -> { nil } + set :sidekiq_user, -> { nil } # Rbenv and RVM integration set :rbenv_map_bins, fetch(:rbenv_map_bins).to_a.concat(%w(sidekiq sidekiqctl)) set :rvm_map_bins, fetch(:rvm_map_bins).to_a.concat(%w(sidekiq sidekiqctl)) From a1f67ed70cf82bb6bd69d11b6e55d682abc2b15f Mon Sep 17 00:00:00 2001 From: Stafford Brunk Date: Wed, 30 Sep 2015 17:31:27 -0400 Subject: [PATCH 4/4] Make sidekiq_user optional in cap2 task like it is in cap3 --- lib/capistrano/tasks/capistrano2.rb | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/lib/capistrano/tasks/capistrano2.rb b/lib/capistrano/tasks/capistrano2.rb index 6888f07..55861e2 100644 --- a/lib/capistrano/tasks/capistrano2.rb +++ b/lib/capistrano/tasks/capistrano2.rb @@ -59,8 +59,12 @@ def for_each_role end def run_as(cmd) + opts = { + roles: sidekiq_role + } su_user = fetch(:sidekiq_user) - run cmd, roles: sidekiq_role, shell: "su - #{su_user}" + opts[:shell] = "su - #{su_user}" if su_user + run cmd, opts end def quiet_process(pid_file, idx, sidekiq_role)