Class: Wakame::Monitor::Service::PidFileChecker

Inherits:
ServiceChecker show all
Defined in:
lib/wakame/monitor/service.rb

Instance Attribute Summary

Attributes inherited from ServiceChecker

#interval, #last_checked_at, #status, #svc_id, #timer

Instance Method Summary collapse

Methods inherited from ServiceChecker

#start, #stop

Constructor Details

#initialize(svc_id, svc_mon, pidpath, interval) ⇒ PidFileChecker

Returns a new instance of PidFileChecker.



83
84
85
86
# File 'lib/wakame/monitor/service.rb', line 83

def initialize(svc_id, svc_mon, pidpath, interval)
  super(svc_id, svc_mon, interval)
  @pidpath = pidpath
end

Instance Method Details

#checkObject



88
89
90
91
92
93
94
95
96
# File 'lib/wakame/monitor/service.rb', line 88

def check
  return Wakame::Service::STATUS_OFFLINE unless File.exist?(@pidpath)
  #cmdstat = ::Open4.popen4("ps -p \"`cat '#{@pidpath}'`\" > /dev/null"){}
  #cmdstat.exitstatus == 0 ? Wakame::Service::STATUS_ONLINE : Wakame::Service::STATUS_OFFLINE

  cmdres = system("ps -p \"`cat '#{@pidpath}'`\" > /dev/null")
  # system() returns true or false.
  cmdres ? Wakame::Service::STATUS_ONLINE : Wakame::Service::STATUS_OFFLINE
end