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

I am booting using a machine using chef. I need it to install a init.d script which it does and when the script is invoked at the end of chef run the script fails on the require 'daemons' line (shown below). I have a print before and after the require and the one before the require is logged.

# my_invoked_script.rb
 $stdout.reopen("output.txt")
 $stderr.reopen("err.txt")
 pid = fork
 if pid.nil?
     puts "Before"
     require 'daemons'
     puts "After"
     ...
 else
   Process.detach(pid)
 end

The before print is logged. The after print is not. I am thinking since this is at boot time some env variables may not be set right. Has anyone been able to run ruby scripts with a require in them at boot time?

My init.d script is a standard script with start function as follows:

start(){
   /usr/local/bin/ruby /home/ubuntu/my_invoked_script.rb
}

Logging into terminal and running the script shows no error and things proceed as normal.

Ruby 1.9.2 ubuntu 11.04 though I am not sure either of them are the issue here.

share|improve this question

1 Answer 1

It could be environment variables, or it could be that the file system with the modules isn't mounted at the time when the script is run.

You could try running with ruby -w to get more information, or you could set the RUBYLIBS environemnt variable before running the ruby script, e.g.

export RUBYLIB="/path/to/lib/ruby"

at the start.

share|improve this answer

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.