From cd32f702b0e3043f14c4d6516b55eefb252e4b6f Mon Sep 17 00:00:00 2001 From: wvengen Date: Tue, 25 Feb 2014 22:49:18 +0100 Subject: [PATCH] fix resque task user switching --- lib/capistrano/tasks/resque.cap | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/lib/capistrano/tasks/resque.cap b/lib/capistrano/tasks/resque.cap index 5d06b5b3..02f9898f 100644 --- a/lib/capistrano/tasks/resque.cap +++ b/lib/capistrano/tasks/resque.cap @@ -9,13 +9,16 @@ namespace :resque do desc "#{action.capitalize} Resque workers" task action => ['deploy:set_rails_env'] do on roles(:resque), in: :groups do - within current_path do - cmd = command(:rake, "resque:#{action}_workers", "RAILS_ENV=#{fetch(:rails_env)}") - if fetch(:run_user).nil? or fetch(:run_user) == local_user - execute cmd + + SSHKit.config.command_map[:rake_as_run_user] = + unless fetch(:run_user).nil? or fetch(:run_user) == fetch(:user) + "sudo -u '#{fetch(:run_user)}' " else - execute 'sudo', '-u', fetch(:run_user), cmd - end + '' + end + SSHKit.config.command_map[:rake] + + within current_path do + execute :rake_as_run_user, "'resque:#{action}_workers'", "RAILS_ENV='#{fetch(:rails_env)}'" end end end