2014-01-15 13:51:24 +01:00
|
|
|
|
|
|
|
# capistrano-resque could be used, but it does not support running resque as another user.
|
|
|
|
# If you want to run resque as another user, setup sudo to allow running commands as that user:
|
|
|
|
# deploy ALL=(foodsoft_user) NOPASSWD: ALL
|
|
|
|
# and set `:run_user` to the foodsoft user.
|
|
|
|
namespace :resque do
|
|
|
|
|
|
|
|
%w{start stop restart}.each do |action|
|
|
|
|
desc "#{action.capitalize} Resque workers"
|
|
|
|
task action => ['deploy:set_rails_env'] do
|
|
|
|
on roles(:resque), in: :groups do
|
2014-02-25 22:49:18 +01:00
|
|
|
|
|
|
|
SSHKit.config.command_map[:rake_as_run_user] =
|
2015-01-14 21:15:08 +01:00
|
|
|
unless fetch(:run_user).nil? || fetch(:run_user) == fetch(:user)
|
2014-02-25 22:49:18 +01:00
|
|
|
"sudo -u '#{fetch(:run_user)}' "
|
2014-01-15 13:51:24 +01:00
|
|
|
else
|
2014-02-25 22:49:18 +01:00
|
|
|
''
|
|
|
|
end + SSHKit.config.command_map[:rake]
|
|
|
|
|
|
|
|
within current_path do
|
|
|
|
execute :rake_as_run_user, "'resque:#{action}_workers'", "RAILS_ENV='#{fetch(:rails_env)}'"
|
2014-01-15 13:51:24 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|