Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
ruby daemon
def daemonize_app
if RUBY_VERSION < "1.9"
exit if fork # jettison the terminal
Process.setsid # establish a new group & session leader (can only be done as a child process)
exit if fork # jettison the group leader. now it can't be interrupted from another group or session going down.
Dir.chdir "/" # change dir to root to make sure that the dir won't go away during the process run
# as a demon we won't be needing these...
STDIN.reopen "/dev/null"
STDOUT.reopen "/dev/null", 'a'
STDERR.reopen "/dev/null", 'a'
else
Process.daemon # :)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.