Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm on a CentOS VPS and using RVM and Capistrano to deploy. for some deployments I need to use sudo, but when I deploy with something like:

desc "Restart the application services"
task :restart, :roles => :app do
  run "#{sudo} cd #{current_path} && bundle exec foreman export upstart"
end

I get: sudo: bundle: command not found. that happens even if I run it manually through SSH. I run all of this under a non root user with sudo privileges and root group.

My sudoers file is like:

Defaults    secure_path = /sbin:/bin:/usr/sbin:/usr/bin

root    ALL=(ALL)    ALL
deploy  ALL=(ALL)  ALL

I tried changing secure_path to:

/usr/local/rvm/gems/ruby-1.9.3-p392/bin:/usr/local/rvm/gems/ruby-1.9.3-p392@global/bin:/usr/local/rvm/rubies/ruby-1.9.3-p392/bin:/usr/local/rvm/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/rvm/bin:/root/bin

Doing that makes the bundle exec part work but now it says sudo: cd: command not found

I'm not sure what to do at this point, any one knows why?

share|improve this question

migrated from stackoverflow.com Mar 20 '13 at 8:26

This question came from our site for professional and enthusiast programmers.

    
What does which sudo get you on the machine, both in the working and non-working states? It sounds like your sudo might be in a weird place. – Jim Stewart Mar 19 '13 at 22:10
    
it's /usr/bin/sudo – user23392 Mar 19 '13 at 22:12
    
Er, actually, I misread the problem. sudo is found; it's bundle that's missing. Make sure you have Bundler installed on the machine. – Jim Stewart Mar 19 '13 at 22:13
    
@Jim i think you misunderstood the issue, Bundler is installed as quoted: Doing that makes the bundle exec part work – user23392 Mar 19 '13 at 22:16

cd isn't an executable; it's a shell built-in, thus the cd: command not found. You're also not quoting your full sudo command, so sudo is only running the part before the &&. Try this:

desc "Restart the application services"
  task :restart, :roles => :app do
    run "#{sudo} sh -c 'cd #{current_path} && bundle exec foreman export upstart'"
  end
end

You can replace sh with whatever shell you prefer, or use $SHELL if it's set.

share|improve this answer

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .