Sha256: bfc42aecdddb274ca7bd5ef77ab79720bfaac54851f244893af08e4f5d3aa34a

Contents?: true

Size: 785 Bytes

Versions: 6

Compression:

Stored size: 785 Bytes

Contents

# CREDIT David Heinemeier Hansson

module Kernel

  # Turns the current script into a daemon process
  # that detaches from the console.
  # It can be shut down with a TERM signal.

  def daemonize
    exit if fork                   # Parent exits, child continues.
    Process.setsid                 # Become session leader.
    exit if fork                   # Zap session leader. See [1].
    Dir.chdir "/"                  # Release old working directory.
    File.umask 0000                # Ensure sensible umask. Adjust as needed.
    STDIN.reopen "/dev/null"       # Free file descriptors and
    STDOUT.reopen "/dev/null", "a" # point them somewhere sensible.
    STDERR.reopen STDOUT           # STDOUT/ERR should better go to a logfile.
    trap("TERM") { exit }
  end

end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
facets-1.8.49 lib/facets/core/kernel/daemonize.rb
facets-1.8.0 lib/facets/core/kernel/daemonize.rb
facets-1.8.20 lib/facets/core/kernel/daemonize.rb
facets-1.8.51 lib/facets/core/kernel/daemonize.rb
facets-1.8.54 lib/facets/core/kernel/daemonize.rb
facets-1.8.8 lib/facets/core/kernel/daemonize.rb