Faster boot with clamav-freshclam.timer

As part of the clamav package, freshclam runs at boot time to download new virus signatures. This slows down booting of the computer considerably.
To my dismay systemd-analyze critical-chain tells me my boot time is prolonged by wait-for-network-online.service (?) of 10-25 sec because clamav-freshclam.service needs to run after network-online.target and before multiuser.target.

How does one update virus signatures in a way that doesn’t slow down boot?

yay -Q clamav
clamav 0.103.2-1
uname -r
5.11.19-1-MANJARO
1 Like

TL;DR:

I sped up my boot by approximately 20 seconds by running freshclam with a systemd.timer instead of the default boot/oneshot/daemon option.

The long version:

freshclam is supposed to update clamav virus signature databases several times per day, but there is no need to update signature databases before even reaching graphical.target.

So i set a systemd.timer to run freshclam every hour by following these guides / bug reports:
Archlinux wiki: Systemd/timers
Fedora bug report for clamav
golinuxcloud: Simple steps to install & configure ClamAV in CentOS 7

After doing so; systemd-analyze reports boot time of 37 secs, which is fast considering my computer had a minimum boot time of 1 minute before this change.

my config, let me know if there’s a better way to do this:

/etc/systemd/system/.#clamav-freshclam.service

[Unit]
Wants=network-online.target
After=network-online.target

Description=ClamAV virus database updater
Documentation=man:freshclam(1) man:freshclam.conf(5) https://www.clamav.net/documents

If user wants it run from cron, don’t start the daemon.

#ConditionPathExists=!/etc/cron.d/clamav-freshclam
#Wants=network-online.target
#After=network-online.target

[Service]
ExecStart=/usr/bin/freshclam
#StandardOutput=syslog

#no need for [install] section due to systemd.timer
#[Install]
#WantedBy=timers.target

/etc/systemd/system/clamav-freshclam.timer

cat /etc/systemd/system/clamav-freshclam.timer

[Unit]
Description=ClamAV virus database updater
After=network-online.target

[Timer]
OnCalendar=--* *:30:00
OnBootSec=16min

[Install]
WantedBy=timers.target

edit: successfully triggered.

$  systemctl status clamav-freshclam.service
● clamav-freshclam.service - ClamAV virus database updater
     Loaded: loaded (/etc/systemd/system/clamav-freshclam.service; static)
    Drop-In: /etc/systemd/system/clamav-freshclam.service.d
             └─override.conf
     Active: inactive (dead) since Sat 2021-05-29 01:30:27 CEST; 8min ago
TriggeredBy: ● clamav-freshclam.timer
       Docs: man:freshclam(1)
             man:freshclam.conf(5)
             https://www.clamav.net/documents
             man:freshclam(1)
             man:freshclam.conf(5)
             https://www.clamav.net/documents
    Process: 427481 ExecStart=/usr/bin/freshclam (code=exited, status=0/SUCCESS)
   Main PID: 427481 (code=exited, status=0/SUCCESS)

mai 29 01:30:27 jacob-satellite-l855 systemd[1]: Started ClamAV virus database updater.
mai 29 01:30:27 jacob-satellite-l855 freshclam[427481]: ClamAV update process started at Sat May 29 01:30:27 2021
mai 29 01:30:27 jacob-satellite-l855 freshclam[427481]: daily.cld database is up-to-date (version: 26184, sigs: 3983619, f-level: 63, builder: raynman)
mai 29 01:30:27 jacob-satellite-l855 freshclam[427481]: main.cvd database is up-to-date (version: 59, sigs: 4564902, f-level: 60, builder: sigmgr)
mai 29 01:30:27 jacob-satellite-l855 freshclam[427481]: bytecode.cvd database is up-to-date (version: 333, sigs: 92, f-level: 63, builder: awillia2)
mai 29 01:30:27 jacob-satellite-l855 systemd[1]: clamav-freshclam.service: Succeeded.
1 Like

Thanks for the tips @Fabby. I’ve got two programs that i haven’t found equivalents for under Linux, so i have to use wine.

  • Epanet (fluid dynamics software)

  • Ecumaster EMU Black (car tuning software)

1 Like

This topic was automatically closed 15 days after the last reply. New replies are no longer allowed.