Capistrano 3 Sudo Password Hangs
Asked Answered
P

2

10

I have the following capistrano 3 task:

desc 'Add root scheduled tasks'
task :root_schedules do
  on roles(:all) do 
    within release_path do
      execute :sudo, :bundle, 'exec whenever -w config/root_schedule.rb -u root'
    end
  end
end

I need this task to run with sudo privileges because I need the scheduled tasks to run with higher privileges. These are backend scheduled server tasks. Problem is that everytime I run this command I get following:

DEBUG [46d3800c]    [sudo] password for [user]

After I type my password and hit enter, it never completes anything. No response at all. Any answers out there?

Patterson answered 19/2, 2015 at 4:50 Comment(0)
V
19

I just created a gem for this purpose: sshkit-sudo

  1. Add gem 'sshkit-sudo' to Gemfile
  2. Add require 'sshkit/sudo' to Capfile

Now you can use sudo command in your Capistrano 3 task.

Varrian answered 25/3, 2015 at 11:28 Comment(4)
I've read info but I'm still wondering how does your gem get sudo password? Does it prompt for it?Paquin
@AlexanderGorg Yes. When a remote server prompts you to input your sudo password, the gem waits for you to type it.Varrian
I'm so grateful to you! It's a really cool gem! I wish you all the best!Paquin
@AlexanderGorg My pleasure. Your words made my day :-)Varrian
B
0

Capistrano kinda expects you to have this handled with a sudoers file, link so that password input is not required.

The direct answer to the question is: capistrano probably uses the default non-login, non-interactive shell. Since the shell is non-interactive, that probably explains why user input is ignored. Read more about this here.

Boomkin answered 19/2, 2015 at 21:47 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.