Last active
August 29, 2015 14:09
-
-
Save jwhiteman/139ce4b5267fcc29b2ef to your computer and use it in GitHub Desktop.
ruby daemon
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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