title: Chef - Run long running script in background
body: <p>I want to run a simple script in the background. It needs to be alive for the duration of the entire life of the machine. </p>
  
  <pre><code>script "my_script" do
  interpreter "ruby"
  cwd "/home/my_home"
  user "root"
  code &lt;&lt; -EOH
    pid = fork
    if pid
       Process.detach(pid)
       system("ruby the_actual_script.rb &gt; logfile")
    end
  EOH
  </code></pre>
  
  <p>But this does not seem to run, it appears it has run and exited immediately. There is a 0 size logfile. I have the cwd folder set to 777 permission. </p>
  
  <p>Can't figure out what the issue is. I am guessing chef executes this in a different shell and gets rid of all processes once it exits that shell? </p>
  
  <p>Is there a better way to simply run the script in the background?</p>