Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Capistrano 2 fixes #109

Merged
merged 4 commits into from
Oct 1, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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