/
clamav-daemon
executable file
·66 lines (55 loc) · 1.54 KB
/
clamav-daemon
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#!/usr/bin/ruby
require 'symbiosis/monitor/check'
class ClamdCheck < Symbiosis::Monitor::Check
def initialize
super
@process.pidfile = "/var/run/clamav/clamd.pid"
@process.initscript = "/etc/init.d/clamav-daemon"
@name = "clamd"
end
#
# This is a monkey-patch for clamav under Jessie, which runs under systemd by
# default, and doesn't write a pidfile. Starting / stopping works via the
# systemd/sysvinit compatibility layer.
#
def running
`systemctl status clamav-daemon.service`
if $? and $?.success?
puts "Found clamav-daemon running via systemctl"
return true
end
super
end
def do_check
#
# Check the initscript. If it is missing, make sure that the process is
# actually suppose to be running, before raising an error.
#
unless initscript_ok?
if should_be_running
return SystemExit::EX_CONFIG
else
puts "Daemon state probably OK -- initscript is missing and #{@name} supposed to be running."
return 0
end
end
r = do_process_check
if SystemExit::EX_TEMPFAIL == r
should_be_running ? self.start : self.stop
end
return r
end
def should_be_running
(0 < Dir.glob('/srv/*/config/antivirus').length)
end
#
# Ignore the test if
# * dpkg if running
# * the initscript is missing and clamav should not be running.
#
def should_ignore?
self.class.dpkg_running? or
(not File.exist?(@process.initscript) and not should_be_running)
end
end
exit ClamdCheck.new.do_check if $0 == __FILE__