1

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.

av501
  • 113
  • 5

1 Answers1

0

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.

Jenny D
  • 27,358
  • 21
  • 74
  • 110