User Tools

Site Tools


archive:freebsd_install_clamav

How To Install ClamAV On FreeBSD

Installing ClamAV

We will install ClamAV from ports. ClamAV updates it’s database every 2 hours unless otherwise defined.

cd /usr/ports/security/clamav
make WITH="LLVM LHA" install clean BATCH=yes

When the options screen pops up hit ok. As for the rest of the popups kust accept the default values.

We need to remove the startup scripts generated by the installation as ClamAV will be supervised by Daemontools.

rm /usr/local/etc/rc.d/clamav-clamd
rm /usr/local/etc/rc.d/clamav-freshclam 

Running ClamAV with Daemontools

Next generate the scripts so we can run clamav through daemontools.

mkdir -m 1755 /var/qmail/supervise/clamav
mkdir -m 1755 /var/qmail/supervise/freshclam
mkdir -m 755 /var/qmail/supervise/clamav/log
mkdir -m 755 /var/qmail/supervise/freshclam/log
mkdir -m 1755 /var/log/qmail/clamav
mkdir -m 1755 /var/log/qmail/freshclam
cd /var/qmail/supervise/clamav
fetch http://www.xfiles.dk/content/files/freebsd-qmail/clamav-run
mv clamav-run run
chmod 755 run
cd log
fetch http://www.xfiles.dk/content/files/freebsd-qmail/clamav-log-run
mv clamav-log-run run
chmod 755 run

Running Freshclam with Daemontools

We do the same for freshclam.

cd /var/qmail/supervise/freshclam
fetch http://www.xfiles.dk/content/files/freebsd-qmail/freshclam-run
mv freshclam-run run
chmod 755 run
cd log
fetch http://www.xfiles.dk/content/files/freebsd-qmail/freshclam-log-run
mv freshclam-log-run run
chmod 755 run

Adjustning the ClamAV config file

We need to edit the clamav config file otherwise it won’t run probably with daemontools.

vi /usr/local/etc/clamd.conf 

Find the following line.

LogFile /var/log/clamav/clamd.log

Mark it as a comment like this.

# LogFile /var/log/clamav/clamd.log

Find this line.

User clamav

Change it to look like this.

User qscand

And finally find this line.

# Foreground yes

And uncomment it like this.

Foreground yes

Adjustning the Freshclam config file

We need to edit the freshclam config file otherwise it won’t run probably with daemontools.

vi /usr/local/etc/freshclam.conf 

Find the following line.

UpdateLogFile /var/log/clamav/freshclam.log

And mark it as a comment like this.

# UpdateLogFile /var/log/clamav/freshclam.log

Find the following line.

DatabaseOwner clamav

And change it to look like this.

DatabaseOwner qscand

And finally find this line.

# Foreground yes

And uncomment it like this.

Foreground yes

Check permissions

chown -R qscand:qscand /var/log/clamav
chown -R qscand:qscand /var/run/clamav/
chown qscand:qscand /var/db/clamav/

Enable the service

ln -s /var/qmail/supervise/clamav /service/
ln -s /var/qmail/supervise/freshclam /service/

Check if everything is working as intended.

svstat /service/freshclam/ /service/freshclam/log

If everything is ok you should get and output like below.

/service/clamav/: up (pid 86635) 19 seconds
/service/clamav/log: up (pid 86636) 19 seconds

Adjust update frequency

Optional Start

If you want to change the how often ClamAV is updating its database then you have to modify the “freshclam.conf” The lines you are looking for looks like this.

# Number of database checks per day.
# Default: 12 (every two hours)
# Checks 24 

Optional Stop

Adding ClamAV to qmailctl

vi /usr/bin/qmailctl

Find the following lines and remove the # in front of all of them.

# if svok /service/clamav ; then
# svc -u /service/clamav /service/clamav/log
# echo "Starting clamav"
# else
# echo "clamav supervise not running"
# fi

# if svok /service/freshclam ; then
# svc -u /service/freshclam /service/freshclam/log
# echo "Starting freshclam"
# else
# echo "freshclam supervise not running"
# fi

# echo " clamav"
# svc -d /service/clamav /service/clamav/log

# echo " freshclam"
# svc -d /service/freshclam /service/freshclam/log

# svstat /service/clamav
# svstat /service/clamav/log

# svstat /service/freshclam
# svstat /service/freshclam/log

# echo "Pausing clamav"
# svc -p /service/clamav

# echo "Pausing freshclam"
# svc -p /service/freshclam

# echo "Pausing clamav"
# svc -c /service/clamav

# eco "Pausing freshclam"
# svc -c /service/freshclam

# echo "* Restarting clamav"
# svc -t /service/clamav /service/clamav/log

# echo "* Restarting freshclam"
# svc -t /service/freshclam /service/freshclam/log

All of the above lines should look like this.

if svok /service/clamav ; then
svc -u /service/clamav /service/clamav/log
echo "Starting clamav"
else
echo "clamav supervise not running"
fi

if svok /service/freshclam ; then
svc -u /service/freshclam /service/freshclam/log
echo "Starting freshclam"
else
echo "freshclam supervise not running"
fi

echo " clamav"
svc -d /service/clamav /service/clamav/log

echo " freshclam"
svc -d /service/freshclam /service/freshclam/log

svstat /service/clamav
svstat /service/clamav/log

svstat /service/freshclam
svstat /service/freshclam/log

echo "Pausing clamav"
svc -p /service/clamav

echo "Pausing freshclam"
svc -p /service/freshclam

echo "Pausing clamav"
svc -c /service/clamav

eco "Pausing freshclam"
svc -c /service/freshclam

echo "* Restarting clamav"
svc -t /service/clamav /service/clamav/log

echo "* Restarting freshclam"
svc -t /service/freshclam /service/freshclam/log
archive/freebsd_install_clamav.txt · Last modified: 24/11/2023 12:33 by Allan