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) ⇒ DaemonProcess

Returns a new instance of DaemonProcess.



3
4
5
6
# File 'lib/rflow/daemon_process.rb', line 3

def initialize(name, role = name)
  @name = name
  @role = role
end

Instance Method Details

#daemonize!Object



8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/rflow/daemon_process.rb', line 8

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



21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/rflow/daemon_process.rb', line 21

def run!
  register_logging_context
  update_process_name
  handle_signals
  spawn_subprocesses
  signal_successful_start

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

#shutdown!(reason) ⇒ Object



37
38
39
40
41
42
# File 'lib/rflow/daemon_process.rb', line 37

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

#spawn_subprocessesObject



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

def spawn_subprocesses; end

#subprocessesObject



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

def subprocesses; []; end