Ruby daemon
mouse 217 · person cloud · link
Last update
2020-04-13
2020
04-13
« — »
1
2
3
4
5
6
7
8
9
10
11
12
13
if RUBY_VERSION >= "1.9"
  Process.daemon
else
  exit if fork    # stop being a process group leader
  Process.setsid  # become a process&session group leader
  exit if fork    # now we can never regain a controlling terminal
  Dir.chdir "/"   # ensure we don't keep any directory in use
  File.umask 0    # have complete control over our files (optional)
  # reopen standard descriptors to oblivion (or where we want)
  STDIN .reopen "/dev/null"
  STDOUT.reopen "/dev/null", "a"
  STDERR.reopen "/dev/null", "a"
end 

Source: stackoverflow linux daemonize, jstorimer.com post, MRI Process.daemon, daemons gem