Class: RFlow::DaemonProcess

Inherits:
Object
  • Object
show all
Defined in:
lib/rflow/daemon_process.rb

Direct Known Subclasses

Master

Instance Method Summary collapse

Constructor Details

#initialize(name, role = name, options = {}) ⇒ DaemonProcess

Returns a new instance of DaemonProcess.



5
6
7
8
9
# File 'lib/rflow/daemon_process.rb', line 5

def initialize(name, role = name, options = {})
  @name = name
  @role = role
  @pid_file = PIDFile.new(options[:pid_file_path]) if options[:pid_file_path]
end

Instance Method Details

#daemonize!Object



11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/rflow/daemon_process.rb', line 11

def daemonize!
  RFlow.logger.info "#{@name} daemonizing"
  establish_daemon_pipe
  drop_database_connections

  parent = fork
  if parent
    exit_after_daemon_starts
  else
    daemonize_process
  end
end

#run!Object



24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/rflow/daemon_process.rb', line 24

def run!
  write_pid_file
  register_logging_context
  update_process_name
  handle_signals
  spawn_subprocesses
  signal_successful_start

  RFlow.logger.info "#{@role} started"
  run_process
ensure
  unhandle_signals
  remove_pid_file
end

#shutdown!(reason) ⇒ Object



42
43
44
45
46
47
48
# File 'lib/rflow/daemon_process.rb', line 42

def shutdown!(reason)
  RFlow.logger.info "#{@name} shutting down due to #{reason}"
  remove_pid_file
  unhandle_signals
  signal_subprocesses('QUIT')
  RFlow.logger.info "#{@name} exiting"
end

#spawn_subprocessesObject



39
# File 'lib/rflow/daemon_process.rb', line 39

def spawn_subprocesses; end

#subprocessesObject



40
# File 'lib/rflow/daemon_process.rb', line 40

def subprocesses; []; end