Class: RTwatchdog::Daemon

Inherits:
Object
  • Object
show all
Defined in:
lib/rt_watchdog/daemon.rb

Instance Method Summary collapse

Instance Method Details

#ramObject



38
39
40
# File 'lib/rt_watchdog/daemon.rb', line 38

def ram
  `#{RTwatchdog::RAM}`.to_i
end

#ram_too_big?Boolean

Returns:

  • (Boolean)


46
47
48
# File 'lib/rt_watchdog/daemon.rb', line 46

def ram_too_big?
  ram > RTwatchdog::MAX_RAM
end

#restartObject



33
34
35
36
# File 'lib/rt_watchdog/daemon.rb', line 33

def restart
  stop
  start
end

#runObject



5
6
7
8
9
10
11
12
13
14
15
16
17
# File 'lib/rt_watchdog/daemon.rb', line 5

def run

  trap('TERM') do
    stop
    exit
  end

  loop do
    start unless running?
    restart if ram_too_big?
    sleep 2
  end
end

#running?Boolean

Returns:

  • (Boolean)


42
43
44
# File 'lib/rt_watchdog/daemon.rb', line 42

def running?
  `#{RTwatchdog::RUNNING}`.length > 0
end

#startObject



19
20
21
# File 'lib/rt_watchdog/daemon.rb', line 19

def start
  `#{RTwatchdog::START}`
end

#stopObject



23
24
25
26
27
28
29
30
31
# File 'lib/rt_watchdog/daemon.rb', line 23

def stop
  begin
    Timeout::timeout RTwatchdog::TIMEOUT do
      `#{RTwatchdog::STOP}`
    end
  rescue Timeout::Error
    `#{RTwatchdog::REALLY_STOP}`
  end
end