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

Returns a new instance of 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

Returns:

  • (Boolean)


39
40
41
42
43
# File 'lib/srv_manager/process.rb', line 39

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

#killObject



24
25
26
27
28
# File 'lib/srv_manager/process.rb', line 24

def kill
  send_signal 'KILL'
  LOGGER.info "Killed process #{@id}"
  @id = nil
end

#restartObject



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

def restart
  stop if alive?
  start
end

#startObject



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

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

#started?Boolean

Returns:

  • (Boolean)


35
36
37
# File 'lib/srv_manager/process.rb', line 35

def started?
  !id.nil?
end

#stopObject



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

def stop
  send_signal 'TERM'
  LOGGER.info "Stoped process #{@id}"
  @id = nil
end