3

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?

4
  • 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. Mar 19, 2013 at 22:10
  • it's /usr/bin/sudo Mar 19, 2013 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. Mar 19, 2013 at 22:13
  • @Jim i think you misunderstood the issue, Bundler is installed as quoted: Doing that makes the bundle exec part work Mar 19, 2013 at 22:16

1 Answer 1

0

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.

You must log in to answer this question.

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