Skip to content

Commit

Permalink
Merge pull request seuros#109 from wingrunr21/cap2_fix
Browse files Browse the repository at this point in the history
Capistrano 2 fixes
  • Loading branch information
seuros committed Oct 1, 2015
2 parents 0d85831 + a1f67ed commit 1c74293
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 3 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
10 changes: 8 additions & 2 deletions lib/capistrano/tasks/capistrano2.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)'
Expand Down
3 changes: 2 additions & 1 deletion lib/capistrano/tasks/sidekiq.rake
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 1c74293

Please sign in to comment.