Class: Daemon::Runner::Fork
- Inherits:
-
Object
- Object
- Daemon::Runner::Fork
- Defined in:
- lib/onapp/engine/runner/fork.rb
Instance Method Summary (collapse)
- - (Object) call(env)
-
- (Fork) initialize(app)
constructor
A new instance of Fork.
Constructor Details
- (Fork) initialize(app)
Returns a new instance of Fork
8 9 10 |
# File 'lib/onapp/engine/runner/fork.rb', line 8 def initialize(app) @app = app end |
Instance Method Details
- (Object) call(env)
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/onapp/engine/runner/fork.rb', line 12 def call(env) prepare = proc do $0 = Daemon::PROCESS_NAME $stderr.extend(Daemon::Utils::IOTimestamp) $stdout.reopen(env.stdout, 'a') if env.stdout $stderr.reopen(env.stderr, 'a') if env.stderr $stdout.sync = $stderr.sync = true trap(::Daemon::MasterProcess::START_SIGNAL) { } end process = proc do begin @app.call(env) rescue Exception => ex $stderr.puts "#{ex.class}: #{ex.}" $stderr.puts ex.backtrace.join("\n") raise ensure Daemon.logger.info 'Exiting...' rescue nil exit! 1 end end pid, = Daemon::Utils::Process.block_and_fork(prepare, 120, &process) [pid, Process.detach(pid)] end |