Sha256: 485be816905961888b587b8cc4b42311009a5da3702f22163961a07e8b212a64

Contents?: true

Size: 899 Bytes

Versions: 16

Compression:

Stored size: 899 Bytes

Contents

module MCollective
  class UnixDaemon
    # Daemonize the current process
    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

    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.main_loop
        rescue => e
          Log.warn(e.backtrace)
          Log.warn(e)
        ensure
          File.unlink(pid) if pid && File.exist?(pid)
        end
      end
    end
  end
end

Version data entries

16 entries across 16 versions & 1 rubygems

Version Path
mcollective-client-2.8.7 lib/mcollective/unix_daemon.rb
mcollective-client-2.8.5 lib/mcollective/unix_daemon.rb
mcollective-client-2.8.6 lib/mcollective/unix_daemon.rb
mcollective-client-2.8.4 lib/mcollective/unix_daemon.rb
mcollective-client-2.8.3 lib/mcollective/unix_daemon.rb
mcollective-client-2.8.2 lib/mcollective/unix_daemon.rb
mcollective-client-2.8.1 lib/mcollective/unix_daemon.rb
mcollective-client-2.8.0 lib/mcollective/unix_daemon.rb
mcollective-client-2.7.0 lib/mcollective/unix_daemon.rb
mcollective-client-2.6.1 lib/mcollective/unix_daemon.rb
mcollective-client-2.6.0 lib/mcollective/unix_daemon.rb
mcollective-client-2.5.3 lib/mcollective/unix_daemon.rb
mcollective-client-2.5.2 lib/mcollective/unix_daemon.rb
mcollective-client-2.5.1 lib/mcollective/unix_daemon.rb
mcollective-client-2.5.0 lib/mcollective/unix_daemon.rb
mcollective-client-2.5.0.rc1 lib/mcollective/unix_daemon.rb