Class: Fluent::Daemonizer

Inherits:
Object
  • Object
show all
Defined in:
lib/fluent/daemonizer.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.daemonize(pid_path, args = [], &block) ⇒ Object



21
22
23
# File 'lib/fluent/daemonizer.rb', line 21

def self.daemonize(pid_path, args = [], &block)
  new.daemonize(pid_path, args, &block)
end

Instance Method Details

#daemonize(pid_path, args = []) ⇒ Object



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/fluent/daemonizer.rb', line 25

def daemonize(pid_path, args = [])
  pid_fullpath = File.absolute_path(pid_path)
  check_pidfile(pid_fullpath)

  begin
    Process.daemon(false, false)

    File.write(pid_fullpath, Process.pid.to_s)

    # install signal and set process name are performed by supervisor
    install_at_exit_handlers(pid_fullpath)

    yield
  rescue NotImplementedError
    daemonize_with_spawn(pid_fullpath, args)
  end
end