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 5ccfc9e..55861e2 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' @@ -57,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) @@ -95,7 +101,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)' diff --git a/lib/capistrano/tasks/sidekiq.rake b/lib/capistrano/tasks/sidekiq.rake index 97f4699..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)) @@ -216,7 +217,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