Skip to content

Instantly share code, notes, and snippets.

@erikh
Created January 25, 2012 07:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save erikh/f9eb9ed1d719e50f1b77 to your computer and use it in GitHub Desktop.
Save erikh/f9eb9ed1d719e50f1b77 to your computer and use it in GitHub Desktop.
def daemonize
trap(:USR1) { exit!(0) }
pid = fork do
ppid = Process.ppid
Process.daemon(true)
begin
Process.kill(:USR1, ppid)
rescue Errno::ESRCH
end
end
if pid
loop { sleep 10 }
end
trap(:USR1, "DEFAULT")
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment