18

I have a capistrano deployment recipe I've been using for some time to deploy my web app and then restart apache/nginx using the sudo command. Recently cap deploy is hanging when I try to execute these sudo commands. I see the output: "[sudo] password for " With my server name and the remote login, but this is not a secure login prompt. The cap shell is just hanging waiting for more output and does not allow me to type my password in to complete the remote sudo command.

Is there a way to fix this or a decent work around? I did not want to remove the sudo password prompt of my remote user for web restart commands.

MikeN
  • 45,039
  • 49
  • 151
  • 227

3 Answers3

32

This seems to happen when connecting to CentOS machines as well. Add the following line in your capistrano deploy file:

default_run_options[:pty] = true

Also make sure to use the sudo helper instead of executing sudo in your run commands directly. For example:

# not
run "sudo chown root:root /etc/my.cnf"

# but
sudo "chown root:root /etc/my.cnf"
wulong
  • 2,657
  • 1
  • 20
  • 19
  • 13
    `sudo` is now deprecated, so instead you should do `run "#{sudo} chown root:root /etc/my.cnf"` – axsuul Feb 21 '12 at 06:24
  • Or use `invoke_command` e.g. `invoke_command "chown root:root /etc/my.cnf", :via => run_method`. Where run_method defines sudo (or not, depending on your `set :use_sudo, true/false`) – Koen. Sep 19 '12 at 08:15
2

The other advice may be sound, but I found that once I updated to Capistrano 2.5.3 the problem went away. I have to make sure I stop running the default versions of tools that came with my O/S.

MikeN
  • 45,039
  • 49
  • 151
  • 227
  • `I have to make sure I stop running the default versions of tools that came with my O/S.` I would stop to use that unstable software stack and start using tools that comes with your OS – hek2mgl Dec 12 '13 at 22:00
2
# prevent sudo prompting for password
set :sudo_prompt, ""
lemats
  • 616
  • 6
  • 5
  • 5
    doesn't that just hide sudo's password prompt? http://rubydoc.info/github/capistrano/capistrano/master/Capistrano/Configuration/Actions/Invocation#sudo_prompt-instance_method – Chris Burgess Feb 20 '12 at 23:24