Class: SrvManager::Process

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(command) ⇒ Process



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

def initialize(command)
  @command = command
end

Instance Attribute Details

#commandObject (readonly)

Returns the value of attribute command.



4
5
6
# File 'lib/srv_manager/process.rb', line 4

def command
  @command
end

#idObject (readonly)

Returns the value of attribute id.



5
6
7
# File 'lib/srv_manager/process.rb', line 5

def id
  @id
end

Instance Method Details

#alive?Boolean



36
37
38
39
40
# File 'lib/srv_manager/process.rb', line 36

def alive?
  started? && ::Process.kill(0, id) ? true : false
rescue Errno::ESRCH
  false
end

#restartObject



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

def restart
  stop if alive?
  start
end

#startObject



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

def start
  return if alive?
  command.rvm ? rvm_start : default_start
  LOGGER.info "Started process #{@id}"
end

#started?Boolean



32
33
34
# File 'lib/srv_manager/process.rb', line 32

def started?
  !id.nil?
end

#stopObject



17
18
19
20
21
22
23
24
25
# File 'lib/srv_manager/process.rb', line 17

def stop
  return unless started?
  begin
    ::Process.kill 'TERM', @id
  rescue Errno::ESRCH
  end
  LOGGER.info "Stoped process #{@id}"
  @id = nil
end