Parent

Class/Module Index [+]

Quicksearch

MCollective::UnixDaemon

Public Class Methods

daemonize() click to toggle source

Daemonize the current process

# File lib/mcollective/unix_daemon.rb, line 4
def self.daemonize
  fork do
    Process.setsid
    exit if fork
    Dir.chdir('/tmp')
    STDIN.reopen('/dev/null')
    STDOUT.reopen('/dev/null', 'a')
    STDERR.reopen('/dev/null', 'a')

    yield
  end
end
daemonize_runner(pid=nil) click to toggle source
# File lib/mcollective/unix_daemon.rb, line 17
def self.daemonize_runner(pid=nil)
  raise "The Unix Daemonizer can not be used on the Windows Platform" if Util.windows?

  UnixDaemon.daemonize do
    if pid
      begin
        File.open(pid, 'w') {|f| f.write(Process.pid) }
      rescue Exception => e
      end
    end

    begin
      runner = Runner.new(nil)
      runner.run
    ensure
      File.unlink(pid) if pid && File.exist?(pid)
    end
  end
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.