I want to write a recipe with Capistrano 3 executing a task on the remote server with sudo.
With Capistrano 2 this could be done for example:
default_run
To resolve this issue I needed to add set :pty, true
to my deploy.rb
file.
I can now run the following:
# config valid only for Capistrano 3.1
lock '3.1.0'
set :application, 'APP_NAME'
set :pty, true
set :ssh_options, {:forward_agent => true}
namespace :deploy do
desc 'Restart NGINX'
task :restart do
on roles(:app), in: :sequence, wait: 1 do
execute :sudo, "./restart.sh"
end
end
end
This task basically runs a shell script called restart.sh
that has a command within sudo service nginx restart
.