clamav unable to create pid file using systemd

Bug #1624262 reported by Oliver Mueller
34
This bug affects 7 people
Affects Status Importance Assigned to Milestone
clamav (Ubuntu)
Expired
Undecided
Unassigned

Bug Description

We are using clamav-daemon as well as clamav-freshclam on Ubuntu 16.04. Because we like to monitor those processes with monit we need the PID files. So when booting the system, we never get the PID files, because the services are unable to write into the default /var/run/clamav folder.

The message in the log files is "ERROR: Can't save PID in file /var/run/clamav/clamd.pid".

When we (re-)start the services manually with e.g. "service clamav-daemon restart", everything works.

There are two different problems here:
1. the init script /etc/init.d/clamav-daemon is changing the permissions on the folder /var/run/clamav no matter if you start/stop/restart or whatsoever, BUT the systemd script used at boot time in /lib/systemd/system/clamav-daemon.service is not. So it won't be able to create the PID file.

2. folder /var/run is a tmpfs and will be created with every reboot, so changing the permissions once, won't last long. The systemd or init script has to change the permissions itself.

So one solutions could be to add the following two lines to /lib/systemd/system/clamav-daemon.service and /lib/systemd/system/clamav-freshclam.service

ExecStartPre=/bin/mkdir -p /var/run/clamav
ExecStartPre=/bin/chown clamav /var/run/clamav

Revision history for this message
Oliver Mueller (oliver-vpr) wrote :

I forgot to mention that the above solution works within our LXC guest environments, but it is not sufficient when running on physical hardware.

It seems, that the clamav startup scripts are executed a bit too early. When they are started, the folder /run or /var/run is not yet a tmpfs. So the PID files will be written to the harddisk instead of the tmpfs. When the system is now putting the tmpfs over /run the PIDs are virtually gone and the monitoring service is unable to see them.

The systemd scripts clamav-daemon.service and clamav-freshclam.service both require clamav-daemon.socket, so it is necessary to postpone the execution of it a little bit. I have added the following line to /lib/systemd/system/clamav-daemon.socket:

After=network.target

Honestly I don't know which service is the best one to wait for here. I just chose network.target, because I knew it is going to be late enough. Maybe someone has a better idea here.

Revision history for this message
Launchpad Janitor (janitor) wrote :

Status changed to 'Confirmed' because the bug affects multiple users.

Changed in clamav (Ubuntu):
status: New → Confirmed
Revision history for this message
Michael Heuberger (michael.heuberger) wrote :

Same here and in conjunction with Monit, causes lots of error log entries

Robie Basak (racb)
tags: added: needs-upstream-report
Revision history for this message
Christian Ehrhardt  (paelzer) wrote :

The systemd service these days doesn't use a pidfile at all anymore.
It uses "normal" systemd handling of a single process service which will poulate $MAINPID that can be referenced from associated systemd services.

You can fetch those via:
systemctl show -p MainPID clamav-daemon

Actually it was that way in Xenial already and I'm not sure how much that is an issue to SRU to trusty.

Revision history for this message
Christian Ehrhardt  (paelzer) wrote :

I came by cleanin gup bugs that were dormant for too long, and I beg your pardon for thise being that way. Yet I hope my explanation helps.

If you think this is really needed for former releases or if I missed sometihng plese set back to new.

Changed in clamav (Ubuntu):
status: Confirmed → Incomplete
Revision history for this message
Launchpad Janitor (janitor) wrote :

[Expired for clamav (Ubuntu) because there has been no activity for 60 days.]

Changed in clamav (Ubuntu):
status: Incomplete → Expired
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.