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
 pid = fork
 if pid.nil?
     puts "Before"
     require 'daemons'
     puts "After"

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:

   /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.


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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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