Sha256: 2542e941c4522964eb83bbf02f4bf3479267d58688fde82ef8e28f257003018d
Contents?: true
Size: 1.33 KB
Versions: 1
Compression:
Stored size: 1.33 KB
Contents
module Cumuli class App class Spawner attr_reader :pid, :env, :log_dir def initialize(env, log_dir) @env = env @log_dir = log_dir ensure_log_dir_and_file end def ensure_log_dir_and_file FileUtils.mkdir_p(log_dir) FileUtils.touch(log_file) end def command "foreman start" end def log_file "#{log_dir}/#{env}.log" end def start @pid = fork do spawn( { 'HEROKU_ENV' => env, 'RAILS_ENV' => env }, command, { out: $stdout.reopen(log_file), pgroup: true, # start a new process group } ) end end def listen_for_signals Cumuli::App::SIGNALS.each do |signal| trap(signal) do puts "#{self.class}: trapped signal #{signal} in #{Process.pid} ... stopping" stop end end end def started? !!pid end def stop return if @killed_it kill_children @killed_it = true @pid = nil end def group_id PS.new.root_pid end def kill_children Process.kill('INT', -group_id) # kills the forked group end end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
cumuli-0.3.4 | lib/cumuli/app/spawner.rb |