Class: Foreman::Process
- Inherits:
-
Object
- Object
- Foreman::Process
- Defined in:
- lib/foreman/process.rb
Instance Attribute Summary collapse
-
#command ⇒ Object
readonly
Returns the value of attribute command.
-
#env ⇒ Object
readonly
Returns the value of attribute env.
Instance Method Summary collapse
-
#alive? ⇒ Boolean
Test whether or not this
Process
is still running. -
#dead? ⇒ Boolean
Test whether or not this
Process
has terminated. -
#initialize(command, options = {}) ⇒ Process
constructor
Create a Process.
-
#kill(signal) ⇒ Object
Send a signal to this
Process
. -
#run(options = {}) ⇒ Object
Run a
Process
.
Constructor Details
#initialize(command, options = {}) ⇒ Process
Create a Process
17 18 19 20 21 22 |
# File 'lib/foreman/process.rb', line 17 def initialize(command, ={}) @command = command @options = .dup @options[:env] ||= {} end |
Instance Attribute Details
#command ⇒ Object (readonly)
Returns the value of attribute command.
6 7 8 |
# File 'lib/foreman/process.rb', line 6 def command @command end |
#env ⇒ Object (readonly)
Returns the value of attribute env.
7 8 9 |
# File 'lib/foreman/process.rb', line 7 def env @env end |
Instance Method Details
#alive? ⇒ Boolean
Test whether or not this Process
is still running
84 85 86 |
# File 'lib/foreman/process.rb', line 84 def alive? kill(0) end |
#dead? ⇒ Boolean
Test whether or not this Process
has terminated
92 93 94 |
# File 'lib/foreman/process.rb', line 92 def dead? !alive? end |
#kill(signal) ⇒ Object
Send a signal to this Process
70 71 72 73 74 75 76 77 78 |
# File 'lib/foreman/process.rb', line 70 def kill(signal) if Foreman.windows? pid && Process.kill(signal, pid) else pid && Process.kill("-#{signal}", pid) end rescue Errno::ESRCH false end |
#run(options = {}) ⇒ Object
Run a Process
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/foreman/process.rb', line 33 def run(={}) env = [:env] ? @options[:env].merge([:env]) : @options[:env] output = [:output] || $stdout if Foreman.windows? Dir.chdir(cwd) do = command.dup env.each do |key, val| .gsub!("$#{key}", val) end Process.spawn env, , :out => output, :err => output end elsif Foreman.jruby? Dir.chdir(cwd) do require "posix/spawn" POSIX::Spawn.spawn env, command, :out => output, :err => output end elsif Foreman.ruby_18? Dir.chdir(cwd) do fork do $stdout.reopen output $stderr.reopen output env.each { |k,v| ENV[k] = v } exec command end end else Dir.chdir(cwd) do Process.spawn env, command, :out => output, :err => output end end end |