Mailing List Archive

[clamav-users] On Access Scanning as a Service
Hello fellow ClamAV users!

I am trying to start clamonacc as a service and have created the following file: /etc/systemd/system/clamonacc.service:

#############
[Unit]
Description=ClamAV On Access Scanner
Requires=clamav-daemon.socket
After=syslog.target network.target clamav-daemon.service

[Service]
Type=simple
User=root
ExecStart=/usr/local/bin/clamonacc -F --log=/var/log/clamav/clamonacc --move=/tmp/quarantine

[Install]
WantedBy=multi-user.target
##############

I can start the service manually no problem ("systemctl start clamonacc") but when I enable it I get the following error on boot:

ERROR: ClamClient: could not connect to remote clam daemon, Couldn't connect to server
ERROR: Clamonacc: daemon is local, but the connection could not be established

I suspect that the problem is that my clamonacc.service is trying to start before the clamav-daemon service/socket is properly up and running (which is why I am able to manually start it after the boot process has completed).

Does anyone have an insight or is there a guide/example clamonacc.service file that I could use/follow?

Thanks,

Glen






Connect with BAE Systems:
https://www.facebook.com/baesystemsplc
https://twitter.com/baesystemsplc
https://www.linkedin.com/company/bae-systems
https://www.youtube.com/user/baesystemsplc

*************************************************************************************
The information contained in this communication may be commercially sensitive and/or legally privileged.
If you have received this message in error please notify the sender or a member of the Communications
team immediately by reply e-mail and then delete this message from your system. You must not disclose
it to any other person or third party who is not on the original distribution.

BAE SYSTEMS MARINE Limited. Registered number is 00229770.
Registered Office: Warwick House, PO Box 87,
Farnborough Aerospace Centre, Farnborough, Hampshire, GU14 6YU


This document contains sensitive information of the United Kingdom Government which is not available in
the public domain in the United Kingdom. It is provided to the United States Government and/or United States
Contractors acting on behalf of the United States Government on the condition that it is not released to the
public without the approval of the United Kingdom Government.

BAE Systems may process information about you that may be subject to data protection laws. For more information about how we use your personal information, how we protect your information, our legal basis for using your information, your rights and who you can contact, please refer to our Privacy Notice at www.baesystems.com/en/privacy

*************************************************************************************
Re: [clamav-users] On Access Scanning as a Service [ In reply to ]
On Mon, 16 Dec 2019, Walker, Glen wrote:

> Hello fellow ClamAV users!
>
> I am trying to start clamonacc as a service and have created the following file: /etc/systemd/system/clamonacc.service:
>
> #############
> [Unit]
> Description=ClamAV On Access Scanner
> Requires=clamav-daemon.socket
> After=syslog.target network.target clamav-daemon.service
>
> [Service]
> Type=simple
> User=root
> ExecStart=/usr/local/bin/clamonacc -F --log=/var/log/clamav/clamonacc --move=/tmp/quarantine
>
> [Install]
> WantedBy=multi-user.target
> ##############
>
> I can start the service manually no problem ("systemctl start clamonacc") but when I enable it I get the following error on boot:
>
> ERROR: ClamClient: could not connect to remote clam daemon, Couldn't connect to server
> ERROR: Clamonacc: daemon is local, but the connection could not be established
>
> I suspect that the problem is that my clamonacc.service is trying to start before the clamav-daemon service/socket is properly up and running (which is why I am able to manually start it after the boot process has completed).
>
> Does anyone have an insight or is there a guide/example clamonacc.service file that I could use/follow?

See the description of Requires= in the systemd.unit man page. It
says:

Note that requirement dependencies do not influence the order
in which services are started or stopped. This has to be
configured independently with the After= or Before= options. If
a unit foo.service requires a unit bar.service as configured
with Requires= and no ordering is configured with After= or
Before=, then both units will be started simultaneously and
without any delay between them if foo.service is activated.
Often, it is a better choice to use Wants= instead of Requires=
in order to achieve a system that is more robust when dealing
with failing services.

So you may need to add clamav-daemon.socket explicitly to the After=
line in the unit file.

Alan Stern


_______________________________________________

clamav-users mailing list
clamav-users@lists.clamav.net
https://lists.clamav.net/mailman/listinfo/clamav-users


Help us build a comprehensive ClamAV guide:
https://github.com/vrtadmin/clamav-faq

http://www.clamav.net/contact.html#ml
Re: [clamav-users] On Access Scanning as a Service [ In reply to ]
Thanks Alan,

Adding "clamav-daemon.socket" to After= didn't work but in the end I got it working by adding a simple restart on failure flag as follows:

##############
[Unit]
Description=ClamAV On Access Scanner
Requires=clamav-daemon.socket clamav-deamon.service
After=clamav-daemon.socket clamav-daemon.service syslog.target network.target

[Service]
Type=simple
User=root
ExecStart=/usr/local/bin/clamonacc -F --log=/var/log/clamav/clamonacc --move=/tmp/quarantine
Restart=on-failure
RestartSec=7s

[Install]
WantedBy=multi-user.target
##############

Hope this is useful to you all! :-)

Glen


----Original Message-----
From: clamav-users [mailto:clamav-users-bounces@lists.clamav.net] On Behalf Of Alan Stern
Sent: 16 December 2019 15:20
To: ClamAV users ML
Subject: Re: [clamav-users] On Access Scanning as a Service

On Mon, 16 Dec 2019, Walker, Glen wrote:

> Hello fellow ClamAV users!
>
> I am trying to start clamonacc as a service and have created the following file: /etc/systemd/system/clamonacc.service:
>
> #############
> [Unit]
> Description=ClamAV On Access Scanner
> Requires=clamav-daemon.socket
> After=syslog.target network.target clamav-daemon.service
>
> [Service]
> Type=simple
> User=root
> ExecStart=/usr/local/bin/clamonacc -F --log=/var/log/clamav/clamonacc --move=/tmp/quarantine
>
> [Install]
> WantedBy=multi-user.target
> ##############
>
> I can start the service manually no problem ("systemctl start clamonacc") but when I enable it I get the following error on boot:
>
> ERROR: ClamClient: could not connect to remote clam daemon, Couldn't connect to server
> ERROR: Clamonacc: daemon is local, but the connection could not be established
>
> I suspect that the problem is that my clamonacc.service is trying to start before the clamav-daemon service/socket is properly up and running (which is why I am able to manually start it after the boot process has completed).
>
> Does anyone have an insight or is there a guide/example clamonacc.service file that I could use/follow?

See the description of Requires= in the systemd.unit man page. It
says:

Note that requirement dependencies do not influence the order
in which services are started or stopped. This has to be
configured independently with the After= or Before= options. If
a unit foo.service requires a unit bar.service as configured
with Requires= and no ordering is configured with After= or
Before=, then both units will be started simultaneously and
without any delay between them if foo.service is activated.
Often, it is a better choice to use Wants= instead of Requires=
in order to achieve a system that is more robust when dealing
with failing services.

So you may need to add clamav-daemon.socket explicitly to the After=
line in the unit file.

Alan Stern


_______________________________________________

clamav-users mailing list
clamav-users@lists.clamav.net
https://lists.clamav.net/mailman/listinfo/clamav-users


Help us build a comprehensive ClamAV guide:
https://github.com/vrtadmin/clamav-faq

http://www.clamav.net/contact.html#ml

Connect with BAE Systems:
https://www.facebook.com/baesystemsplc
https://twitter.com/baesystemsplc
https://www.linkedin.com/company/bae-systems
https://www.youtube.com/user/baesystemsplc

*************************************************************************************
The information contained in this communication may be commercially sensitive and/or legally privileged.
If you have received this message in error please notify the sender or a member of the Communications
team immediately by reply e-mail and then delete this message from your system. You must not disclose
it to any other person or third party who is not on the original distribution.

BAE SYSTEMS MARINE Limited. Registered number is 00229770.
Registered Office: Warwick House, PO Box 87,
Farnborough Aerospace Centre, Farnborough, Hampshire, GU14 6YU


This document contains sensitive information of the United Kingdom Government which is not available in
the public domain in the United Kingdom. It is provided to the United States Government and/or United States
Contractors acting on behalf of the United States Government on the condition that it is not released to the
public without the approval of the United Kingdom Government.

BAE Systems may process information about you that may be subject to data protection laws. For more information about how we use your personal information, how we protect your information, our legal basis for using your information, your rights and who you can contact, please refer to our Privacy Notice at www.baesystems.com/en/privacy

*************************************************************************************

_______________________________________________

clamav-users mailing list
clamav-users@lists.clamav.net
https://lists.clamav.net/mailman/listinfo/clamav-users


Help us build a comprehensive ClamAV guide:
https://github.com/vrtadmin/clamav-faq

http://www.clamav.net/contact.html#ml