Module: Eye::Process::System

Included in:
ChildProcess, Eye::Process
Defined in:
lib/eye/process/system.rb

Instance Method Summary collapse

Instance Method Details

#clear_pid_fileObject



27
28
29
30
31
32
# File 'lib/eye/process/system.rb', line 27

def clear_pid_file
  File.unlink(self[:pid_file_ex])
  true
rescue 
  nil
end

#execute(cmd, cfg = {}) ⇒ Object



59
60
61
# File 'lib/eye/process/system.rb', line 59

def execute(cmd, cfg = {})
  defer{ Eye::System::execute cmd, cfg }
end

#failsafe_load_pidObject



63
64
65
66
67
68
69
70
71
72
73
# File 'lib/eye/process/system.rb', line 63

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_pidObject



75
76
77
78
79
80
81
# File 'lib/eye/process/system.rb', line 75

def failsafe_save_pid
  save_pid_to_file 
  true
rescue => ex
  error "failsafe_save_pid: #{ex.message}"
  false
end

#load_pid_from_fileObject



5
6
7
8
9
10
# 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_ctimeObject



34
35
36
# File 'lib/eye/process/system.rb', line 34

def pid_file_ctime
  File.ctime(self[:pid_file_ex]) rescue Time.now
end

#process_realy_running?Boolean

Returns:

  • (Boolean)


38
39
40
41
42
# File 'lib/eye/process/system.rb', line 38

def process_realy_running?
  res = Eye::System.check_pid_alive(self.pid)
  debug "process_realy_running?: (#{self.pid}) #{res.inspect}"
  !!res[:result]
end

#save_pid_to_fileObject



16
17
18
19
20
21
22
23
24
25
# 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) ⇒ Object



44
45
46
47
48
49
50
51
52
# File 'lib/eye/process/system.rb', line 44

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_fileObject



12
13
14
# 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, &block) ⇒ Object

non blocking actor timeout



55
56
57
# File 'lib/eye/process/system.rb', line 55

def wait_for_condition(timeout, step = 0.1, &block)
  defer{ wait_for_condition_sync(timeout, step, &block) }
end