Capistrano 3 - Error: Sorry, you must have tty to run sudo

I just updated Capistrano from v2 to version v3.1.

I rewrote my tasks, including one that launches a shell script that restarts NGINX among other things. To restart NGINX, I have to work as sudo , which causes an error:

Sorry, you must have TTY to run sudo

In Capistrano 2, to solve this problem, I added to my Capfile:

default_run_options[:pty] = true

What is equivalent for Capistrano v3?

My deploy.rb file looks like this:

 # config valid only for Capistrano 3.1 lock '3.1.0' set :application, 'APP_NAME' namespace :deploy do desc 'Restart NGINX' task :restart do on roles(:app), in: :sequence, wait: 5 do execute :sudo, "./restart.sh" end end end 
+7
ruby capistrano capistrano3
source share
1 answer

To solve this problem, I need to add set :pty, true to my deploy.rb file. I had to delve into several places to find this answer, so I thought that I would share that someone else had the same problem.

Updated deploy.rb file

 # config valid only for Capistrano 3.1 lock '3.1.0' set :application, 'APP_NAME' set :pty, 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 

To connect without asking for a password, you need to configure SSH keys. My production.rb and staging.rb look something like this:

 set :stage, :production role :app, %{ec2-000-000-000-000.eu-west-1.compute.amazonaws.com} set :ssh_options, { user: 'ubuntu', keys: %w(/path/to/key/file/my_access_key.pem), forward_agent: false } 
+13
source share

All Articles