|
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: |