Sha256: 46361561ed78bfceca87f6e7085bc2ae41990045906c314af1451c2d4ceeb94b

Contents?: true

Size: 1.31 KB

Versions: 17

Compression:

Stored size: 1.31 KB

Contents

# = Daemonize
#
# Turns the current script into a daemon process
# that detaches from the console.
# It can be shut down with a TERM signal.
#
# == Authors
#
# * David Heinemeier Hansson
#
# == Copying
#
#   Copyright (c) 2006 David Heinemeier Hansson
#
#   Ruby License
#
#   This module is free software. You may use, modify, and/or redistribute this
#   software under the same terms as Ruby.
#
#   This program is distributed in the hope that it will be useful, but WITHOUT
#   ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
#   FOR A PARTICULAR PURPOSE.

#
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

17 entries across 17 versions & 2 rubygems

Version Path
facets-2.8.4 lib/more/facets/daemonize.rb
facets-2.8.3 lib/more/facets/daemonize.rb
facets-2.8.2 lib/more/facets/daemonize.rb
facets-2.8.1 lib/more/facets/daemonize.rb
facets-2.8.0 lib/more/facets/daemonize.rb
facets-2.7.0 lib/more/facets/daemonize.rb
facets-2.6.0 lib/more/facets/daemonize.rb
facets-2.4.0 lib/facets/daemonize.rb
facets-2.4.1 lib/facets/daemonize.rb
facets-2.4.3 lib/more/facets/daemonize.rb
facets-2.4.4 lib/more/facets/daemonize.rb
facets-2.4.2 lib/more/facets/daemonize.rb
facets-2.5.1 lib/more/facets/daemonize.rb
facets-2.5.0 lib/more/facets/daemonize.rb
facets-2.4.5 lib/more/facets/daemonize.rb
facets-2.5.2 lib/more/facets/daemonize.rb
mack-facets-0.8.2 lib/gems/facets-2.4.5/lib/more/facets/daemonize.rb