Class: Alt::Foreman::Process
- Inherits:
-
Object
- Object
- Alt::Foreman::Process
- Defined in:
- lib/alt-foreman/process.rb
Instance Attribute Summary collapse
-
#cmd ⇒ Object
readonly
Returns the value of attribute cmd.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#pid ⇒ Object
readonly
Returns the value of attribute pid.
Instance Method Summary collapse
-
#initialize(name, cmd) ⇒ Process
constructor
A new instance of Process.
- #log(info, col = nil) ⇒ Object
- #run ⇒ Object
Constructor Details
#initialize(name, cmd) ⇒ Process
Returns a new instance of Process.
7 8 9 |
# File 'lib/alt-foreman/process.rb', line 7 def initialize(name, cmd) @name, @cmd = name, cmd end |
Instance Attribute Details
#cmd ⇒ Object (readonly)
Returns the value of attribute cmd.
6 7 8 |
# File 'lib/alt-foreman/process.rb', line 6 def cmd @cmd end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
6 7 8 |
# File 'lib/alt-foreman/process.rb', line 6 def name @name end |
#pid ⇒ Object (readonly)
Returns the value of attribute pid.
6 7 8 |
# File 'lib/alt-foreman/process.rb', line 6 def pid @pid end |
Instance Method Details
#log(info, col = nil) ⇒ Object
10 11 12 |
# File 'lib/alt-foreman/process.rb', line 10 def log(info, col = nil) Alt::Foreman.log(@name, info, col) end |
#run ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/alt-foreman/process.rb', line 13 def run args = Shellwords.split(@cmd) args.each_with_index do |arg, index| if arg =~ /-p(\d+)/ Foreman.kill_tcp_server!($1, @name) elsif arg == '-p' && args[index+1] =~ /\d+/ Foreman.kill_tcp_server!(args[index+1], @name) end end IO.popen(@cmd, 'rb') do |io| @pid = io.pid while line = io.gets log(line) Thread.pass end end end |