Skip to content

Commit

Permalink
Update the old clamav tests to check process with systemctl
Browse files Browse the repository at this point in the history
This extra bit of code calls `systemctl` to see if the clam processes
are running, rather than checking the pidfile.  This command exits zero
if the service is running.

 If systemctl is unsuccessful for *any* reason, then fall back on
checking the pidfile.

Starting/stopping the processes still works via the sysvinit
compatibility layer.

If systemd is not running, the systemctl command displays

    Failed to get D-Bus connection: Unknown error -1

and exits non-zero, so we continue on to the pidfile check.

This closes #49.
  • Loading branch information
Patrick J Cherry committed Jul 7, 2017
1 parent 283b60a commit fe97535
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 5 deletions.
23 changes: 19 additions & 4 deletions email/symbiosis/monit.d/clamav-daemon
Expand Up @@ -11,6 +11,21 @@ class ClamdCheck < Symbiosis::Monitor::Check
@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
Expand All @@ -26,7 +41,7 @@ class ClamdCheck < Symbiosis::Monitor::Check
end

r = do_process_check
if SystemExit::EX_TEMPFAIL == r
if SystemExit::EX_TEMPFAIL == r
should_be_running ? self.start : self.stop
end
return r
Expand All @@ -37,12 +52,12 @@ class ClamdCheck < Symbiosis::Monitor::Check
end

#
# Ignore the test if
# * dpkg if running
# 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
self.class.dpkg_running? or
(not File.exist?(@process.initscript) and not should_be_running)
end
end
Expand Down
17 changes: 16 additions & 1 deletion email/symbiosis/monit.d/clamav-freshclam
Expand Up @@ -11,6 +11,21 @@ class FreshclamCheck < Symbiosis::Monitor::Check
@name = "freshclam"
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-freshclam.service`
if $? and $?.success?
puts "Found clamav-freshclam running via systemctl"
return true
end

super
end

def do_check
#
# Check the initscript. If it is missing, make sure that the process is
Expand All @@ -26,7 +41,7 @@ class FreshclamCheck < Symbiosis::Monitor::Check
end

r = do_process_check
if SystemExit::EX_TEMPFAIL == r
if SystemExit::EX_TEMPFAIL == r
should_be_running ? self.start : self.stop
end
return r
Expand Down

0 comments on commit fe97535

Please sign in to comment.