You are not logged in.

#1 2016-11-21 10:14:11

fdservices
Member
From: France
Registered: 2012-02-06
Posts: 413

Help with Systemd Timers [SOLVED]

I have two systemd timers relating to clamav: clamd.timer and freshclamd.timer
clamd.timer

[Unit]
Description=Runs clamd after 2 minutes 

[Timer]
# Time to wait after booting before we run first time
OnBootSec=2min
Unit=clamd.service

[Install]
WantedBy=basic.target

freshclamd.timer

[Unit]
Description=Runs freshclamd after 3 minutes

[Timer]
# Time to wait after booting before we run first time
OnBootSec=3min
Unit=freshclamd.service

[Install]
WantedBy=basic.target

Both have been enabled, freshclam runs ok, but clamd does not run.

# systemctl list-timers
NEXT                         LEFT      LAST                         PASSED       UNIT                         ACTIVATES
n/a                          n/a       Mon 2016-11-21 10:51:12 CET  17min ago    clamd.timer                  clamd.service
Mon 2016-11-21 10:51:57 CET  17min ago Mon 2016-11-21 10:52:12 CET  16min ago    freshclamd.timer             freshclamd.service
Tue 2016-11-22 00:00:00 CET  12h left  Mon 2016-11-21 08:40:28 CET  2h 28min ago logrotate.timer              logrotate.service
Tue 2016-11-22 00:00:00 CET  12h left  Mon 2016-11-21 08:40:28 CET  2h 28min ago man-db.timer                 man-db.service
Tue 2016-11-22 00:00:00 CET  12h left  Mon 2016-11-21 08:40:28 CET  2h 28min ago shadow.timer                 shadow.service
Tue 2016-11-22 00:00:00 CET  12h left  Mon 2016-11-21 11:04:08 CET  5min ago     updatedb.timer               updatedb.service
Tue 2016-11-22 11:04:08 CET  23h left  Mon 2016-11-21 11:04:08 CET  5min ago     systemd-tmpfiles-clean.timer systemd-tmpfiles-clean

7 timers listed.

I suspect that the "n/a" has something to do with it

As always, any help would be appreciated

Andrew

Last edited by fdservices (2016-11-22 09:27:19)

Offline

#2 2016-11-21 12:30:53

Raynman
Member
Registered: 2011-10-22
Posts: 1,539

Re: Help with Systemd Timers [SOLVED]

Well, if you check LAST and PASSED, it looks good. Presumably you booted 19 min ago and then those timers were triggered after 2 and 3 mins. But you say clamd does not actually run; does

$ systemctl status clamd.{timer,service}

(or the journal) provide any useful info?

The only trigger you specified is the one after booting. So the next time would be "after the next boot" and I don't understand the NEXT/LEFT values for freshclamd.timer. The n/a for clamd.timer doesn't exactly say "after next boot", but IMHO it's not as strange as having the next run be in the past.

Last edited by Raynman (2016-11-21 12:32:19)

Offline

#3 2016-11-22 08:25:54

fdservices
Member
From: France
Registered: 2012-02-06
Posts: 413

Re: Help with Systemd Timers [SOLVED]

$ systemctl status clamd.{timer,service}
● clamd.timer - Runs clamd after 2 minutes
   Loaded: loaded (/etc/systemd/system/clamd.timer; enabled; vendor preset: disabled)
   Active: active (elapsed) since Mon 2016-11-21 10:49:11 CET; 22h ago

Nov 21 10:49:11 acer systemd[1]: Started Runs clamd after 2 minutes.

● clamd.service - clamav daemon
   Loaded: loaded (/etc/systemd/system/clamd.service; disabled; vendor preset: disabled)
   Active: failed (Result: timeout) since Mon 2016-11-21 10:51:22 CET; 22h ago
  Process: 767 ExecStart=/usr/bin/clamd (code=killed, signal=TERM)

Nov 21 10:51:12 acer systemd[1]: Starting clamav daemon...
Nov 21 10:51:22 acer systemd[1]: clamd.service: Start operation timed out. Terminating.
Nov 21 10:51:22 acer systemd[1]: Failed to start clamav daemon.
Nov 21 10:51:22 acer systemd[1]: clamd.service: Unit entered failed state.
Nov 21 10:51:22 acer systemd[1]: clamd.service: Failed with result 'timeout'.

It is clear that clamd failed to run - timeout, but why? If I run /usr/bin/clamd manually it starts OK.

I suppose I could add some commands such as

Restart=on-failure
RestartSec=10

but why should that be necessary?

Andrew

Offline

#4 2016-11-22 09:26:38

fdservices
Member
From: France
Registered: 2012-02-06
Posts: 413

Re: Help with Systemd Timers [SOLVED]

OK, the clue was in the "timeout" message.

In order to stop the "A stop job is running for session c1" at shutdown taking 90 seconds to continue I changed the default value to 10 seconds.

In /etc/systemd/system.conf
From:
#DefaultTimeoutStartSec=90s
#DefaultTimeoutStopSec=90s
To:
DefaultTimeoutStartSec=10s
DefaultTimeoutStopSec=10s

But clamd takes around 20 seconds to start on my machine, so I added "TimeoutStartSec=30" to the service file, and all is now well.

Thanks for the help

Andrew

Offline

#5 2017-05-18 19:42:36

rod_d
Member
Registered: 2014-07-06
Posts: 2

Re: Help with Systemd Timers [SOLVED]

Thanks Andrew!

clamd was timing out on me for the same reason (I modified DefaultTimeoutStart(Stop)Sec to prevent lengthy shutdowns).

Additionally there is a well know issue with clamd not being compatible with yara modules and thus throwing a number of error messages when it tries to parse yara rules upon starting the daemon (which threw me off initially when looking for a solution):

clamd[489]: LibClamAV Error: yyerror(): /var/lib/clamav/antidebug_antivm.yar line 497 undefined identifier "pe"
clamd[489]: LibClamAV Error: yyerror(): /var/lib/clamav/antidebug_antivm.yar line 512 undefined identifier "pe"
clamd[489]: LibClamAV Error: yyerror(): /var/lib/clamav/antidebug_antivm.yar line 528 undefined identifier "pe"
clamd[489]: LibClamAV Error: yyerror(): /var/lib/clamav/antidebug_antivm.yar line 544 undefined identifier "pe"
clamd[489]: LibClamAV Error: yyerror(): /var/lib/clamav/antidebug_antivm.yar line 557 undefined identifier "pe"
clamd[489]: LibClamAV Error: yyerror(): /var/lib/clamav/antidebug_antivm.yar line 603 undefined identifier "pe"
clamd[489]: LibClamAV Error: yyerror(): /var/lib/clamav/antidebug_antivm.yar line 614 undefined identifier "pe"
clamd[489]: LibClamAV Error: cli_loadyara: failed to parse rules file /var/lib/clamav/antidebug_antivm.yar, error count 7

However, clamd starts successfully given enough time and these errors can be ignored for now.  Thanks to your post for reminding me that the timeout error I was getting was related to my /etc/systemd/system.conf settings.  Your fix to add "TimeoutStartSec=30" to the clamd service file is spot on.  There is no need to go back to slow reboots.

~~~~~~~~~~
Allow me to show each step here to the next person who may have this issue. To overlay this command onto a systemd service file without touching the original https://wiki.archlinux.org/index.php/sy … p-in_files:

$ sudo systemctl edit clamd

This opens your editor and creates /etc/systemd/system/clamd.service.d/override.conf. You only need one line:

TimeoutStartSec=30

Save and exit.

$ sudo systemctl restart clamd

It should work now. Double check.  The errors may still be there for now, but the service starts without timing out.

$ sudo systemctl status clamd

Thanks again.

Last edited by rod_d (2017-05-18 19:48:50)

Offline

Board footer

Powered by FluxBB