Error
  • JHTMLicon not supported. File not found.
  • JHTMLicon not supported. File not found.
  • JHTMLicon not supported. File not found.

$stdout

Daemonize a Ruby process
Thursday, 15 December 2011 12:26
Neat separation of responsibilities between fork/process stuff and actual app


#!/usr/bin/ruby

daemonize do
worker = Resque::Worker.new(*queues)
worker.work
end

def daemonize &block
child = fork
if child.nil? # is child
$stdout.close
$stdout = open("/dev/null")
$stdin.close
trap('HUP', 'IGNORE')
block.call
else # is parent
Process.detach child
end
end

Read more: http://feeds.dzone.com/~r/dzone/snippets/~3/8RoOygYj_Co/14203

 


Taxonomy by Zaragoza Online