Class: Cumuli::App::ForemanProcess
- Inherits:
-
Object
- Object
- Cumuli::App::ForemanProcess
- Defined in:
- lib/cumuli/app/foreman_process.rb
Instance Attribute Summary collapse
-
#env ⇒ Object
readonly
Returns the value of attribute env.
-
#log_dir ⇒ Object
readonly
Returns the value of attribute log_dir.
-
#pid ⇒ Object
readonly
Returns the value of attribute pid.
Instance Method Summary collapse
- #command ⇒ Object
- #ensure_log_dir_and_file ⇒ Object
-
#initialize(env, log_dir) ⇒ ForemanProcess
constructor
A new instance of ForemanProcess.
- #kill_children ⇒ Object
- #listen_for_signals ⇒ Object
- #log_file ⇒ Object
- #start ⇒ Object
- #started? ⇒ Boolean
- #stop ⇒ Object
Constructor Details
#initialize(env, log_dir) ⇒ ForemanProcess
Returns a new instance of ForemanProcess.
6 7 8 9 10 |
# File 'lib/cumuli/app/foreman_process.rb', line 6 def initialize(env, log_dir) @env = env @log_dir = log_dir ensure_log_dir_and_file end |
Instance Attribute Details
#env ⇒ Object (readonly)
Returns the value of attribute env.
4 5 6 |
# File 'lib/cumuli/app/foreman_process.rb', line 4 def env @env end |
#log_dir ⇒ Object (readonly)
Returns the value of attribute log_dir.
4 5 6 |
# File 'lib/cumuli/app/foreman_process.rb', line 4 def log_dir @log_dir end |
#pid ⇒ Object (readonly)
Returns the value of attribute pid.
4 5 6 |
# File 'lib/cumuli/app/foreman_process.rb', line 4 def pid @pid end |
Instance Method Details
#command ⇒ Object
17 18 19 |
# File 'lib/cumuli/app/foreman_process.rb', line 17 def command "HEROKU_ENV=#{env} RAILS_ENV=#{env} foreman start" end |
#ensure_log_dir_and_file ⇒ Object
12 13 14 15 |
# File 'lib/cumuli/app/foreman_process.rb', line 12 def ensure_log_dir_and_file FileUtils.mkdir_p(log_dir) FileUtils.touch(log_file) end |
#kill_children ⇒ Object
53 54 55 56 57 58 |
# File 'lib/cumuli/app/foreman_process.rb', line 53 def kill_children pids = PS.new.tree(pid) pids.reverse.each do |p| Process.kill("KILL", p) end end |
#listen_for_signals ⇒ Object
33 34 35 36 37 38 39 40 |
# File 'lib/cumuli/app/foreman_process.rb', line 33 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 |
#log_file ⇒ Object
21 22 23 |
# File 'lib/cumuli/app/foreman_process.rb', line 21 def log_file "#{log_dir}/#{env}.log" end |
#start ⇒ Object
25 26 27 28 29 30 31 |
# File 'lib/cumuli/app/foreman_process.rb', line 25 def start @pid = fork do listen_for_signals $stdout.reopen(log_file) exec(command) end end |
#started? ⇒ Boolean
42 43 44 |
# File 'lib/cumuli/app/foreman_process.rb', line 42 def started? !!pid end |
#stop ⇒ Object
46 47 48 49 50 51 |
# File 'lib/cumuli/app/foreman_process.rb', line 46 def stop return if @killed_it kill_children @killed_it = true @pid = nil end |