Take the 2-minute tour ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

My context:

  • ruby-enterprise 1.8.7, on a CentOS 5
  • ruby and gem are installed in /usr/local/bin
  • ./runner: runs correctly
  • sudo ./runner

    Rails requires RubyGems >= 1.3.2. Please install RubyGems and try again: http://rubygems.rubyforge.org

    (because sudo has a limited PATH)

  • sudo PATH=$PATH ./runner: runs correctly, as runner has /usr/local/bin in its PATH again

Question:

Are there other alternatives (possibly more elegant - with minimal changes) to launch runner with sudo, when gem is not in /bin or /usr/bin ?

Those I would think of (but not satisfied with):

  • putting a symlink to gem in /usr/bin
  • modifying runner ?
  • modifying sudoers ?

Maybe there is a way with a config file or a command line argument to runner ?

share|improve this question

1 Answer 1

up vote 2 down vote accepted

You should be able to use the env_file option in sudoers and put your path specification in a file that it points to. Something like:

sudoers:

Cmnd_Alias    RUBY = /path/to/runner
Defaults!RUBY env_file=/path/to/rubypathfile
ALL ALL=(ALL) RUBY

/path/to/rubypathfile:

PATH=/usr/local/bin:/usr/bin:/bin

You may also find the env_keep option useful.

Take a look at sudo sudo -V | less and see if it tells you anything of interest. Particularly do a case-insensitive search for "path" or "ruby".

share|improve this answer
    
Thanks Dennis, especially for the sudo sudo -V tip. –  David142 Aug 27 '10 at 8:57

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.