Daemonize A Ruby Process
Join the DZone community and get the full member experience.Join For Free
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
Opinions expressed by DZone contributors are their own.