Class: Foreman::Process

Inherits:
Object
  • Object
show all
Defined in:
lib/foreman/process.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(entry, num, port) ⇒ Process

Returns a new instance of Process.



11
12
13
14
15
# File 'lib/foreman/process.rb', line 11

def initialize(entry, num, port)
  @entry = entry
  @num = num
  @port = port
end

Instance Attribute Details

#entryObject (readonly)

Returns the value of attribute entry.



6
7
8
# File 'lib/foreman/process.rb', line 6

def entry
  @entry
end

#numObject (readonly)

Returns the value of attribute num.



7
8
9
# File 'lib/foreman/process.rb', line 7

def num
  @num
end

#pidObject (readonly)

Returns the value of attribute pid.



8
9
10
# File 'lib/foreman/process.rb', line 8

def pid
  @pid
end

#portObject (readonly)

Returns the value of attribute port.



9
10
11
# File 'lib/foreman/process.rb', line 9

def port
  @port
end

Instance Method Details

#alive?Boolean

Returns:

  • (Boolean)


37
38
39
# File 'lib/foreman/process.rb', line 37

def alive?
  kill(0)
end

#dead?Boolean

Returns:

  • (Boolean)


41
42
43
# File 'lib/foreman/process.rb', line 41

def dead?
  !alive?
end

#detachObject



33
34
35
# File 'lib/foreman/process.rb', line 33

def detach
  pid && Process.detach(pid)
end

#kill(signal) ⇒ Object



27
28
29
30
31
# File 'lib/foreman/process.rb', line 27

def kill(signal)
  pid && Process.kill(signal, pid)
rescue Errno::ESRCH
  false
end

#nameObject



23
24
25
# File 'lib/foreman/process.rb', line 23

def name
  "%s.%s" % [ entry.name, num ]
end

#run(pipe, basedir, environment) ⇒ Object



17
18
19
20
21
# File 'lib/foreman/process.rb', line 17

def run(pipe, basedir, environment)
  with_environment(environment.merge("PORT" => port.to_s)) do
    run_process basedir, entry.command, pipe
  end
end