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

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

Instance Attribute Summary

Attributes inherited from ServiceChecker

#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) ⇒ PidFileChecker

Returns a new instance of PidFileChecker.



78
79
80
81
# File 'lib/wakame/monitor/service.rb', line 78

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

Instance Method Details

#checkObject



83
84
85
86
87
88
89
90
91
# File 'lib/wakame/monitor/service.rb', line 83

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