module Eye::Process::System

Public Instance Methods

clear_pid_file() click to toggle source
# File lib/eye/process/system.rb, line 27
def clear_pid_file
  info "delete pid_file: #{self[:pid_file_ex]}"
  File.unlink(self[:pid_file_ex])
  true
rescue
  nil
end
execute(cmd, cfg = {}) click to toggle source
# File lib/eye/process/system.rb, line 73
def execute(cmd, cfg = {})
  defer{ Eye::System::execute cmd, cfg }
end
failsafe_load_pid() click to toggle source
# File lib/eye/process/system.rb, line 77
def failsafe_load_pid
  pid = load_pid_from_file

  if !pid
    # this is can be symlink changed case
    sleep 0.1
    pid = load_pid_from_file
  end

  pid
end
failsafe_save_pid() click to toggle source
# File lib/eye/process/system.rb, line 89
def failsafe_save_pid
  save_pid_to_file
  true
rescue => ex
  log_ex(ex)
  false
end
load_pid_from_file() click to toggle source
# File lib/eye/process/system.rb, line 5
def load_pid_from_file
  if File.exists?(self[:pid_file_ex])
    _pid = File.read(self[:pid_file_ex]).to_i
    _pid > 0 ? _pid : nil
  end
end
pid_file_ctime() click to toggle source
# File lib/eye/process/system.rb, line 35
def pid_file_ctime
  File.ctime(self[:pid_file_ex]) rescue Time.now
end
process_pid_running?(pid) click to toggle source
# File lib/eye/process/system.rb, line 43
def process_pid_running?(pid)
  res = Eye::System.check_pid_alive(pid)
  debug "process_really_running?: (#{pid}) #{res.inspect}"
  !!res[:result]
end
process_really_running?() click to toggle source
# File lib/eye/process/system.rb, line 39
def process_really_running?
  process_pid_running?(self.pid)
end
save_pid_to_file() click to toggle source
# File lib/eye/process/system.rb, line 16
def save_pid_to_file
  if self.pid
    File.open(self[:pid_file_ex], 'w') do |f|
      f.write self.pid
    end
    true
  else
    false
  end
end
send_signal(code) click to toggle source
# File lib/eye/process/system.rb, line 49
def send_signal(code)
  res = Eye::System.send_signal(self.pid, code)

  msg = "send_signal #{code} to #{self.pid}"
  msg += ", error<#{res[:error]}>" if res[:error]
  info msg

  res[:result] == :ok
end
set_pid_from_file() click to toggle source
# File lib/eye/process/system.rb, line 12
def set_pid_from_file
  self.pid = load_pid_from_file
end
wait_for_condition(timeout, step = 0.1) { || ... } click to toggle source
# File lib/eye/process/system.rb, line 59
def wait_for_condition(timeout, step = 0.1, &block)
  res = nil
  sumtime = 0

  loop do
    tm = Time.now
    res = yield # note that yield can block actor here and timeout can be overhead
    return res if res
    sleep step.to_f
    sumtime += (Time.now - tm)
    return false if sumtime > timeout
  end
end