Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
Bug 681872 - mail-filter/spamassassin: /etc/cron.daily/update-spamassassin-rules attempts to restart amavisd even if not installed
Summary: mail-filter/spamassassin: /etc/cron.daily/update-spamassassin-rules attempts ...
Status: RESOLVED FIXED
Alias: None
Product: Gentoo Linux
Classification: Unclassified
Component: Current packages (show other bugs)
Hardware: All Linux
: Normal normal (vote)
Assignee: Philippe Chaintreuil
URL:
Whiteboard:
Keywords: PullRequest
Depends on:
Blocks:
 
Reported: 2019-03-27 18:27 UTC by Dan Goodliffe
Modified: 2024-01-27 08:50 UTC (History)
4 users (show)

See Also:
Package list:
Runtime testing required: ---


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Dan Goodliffe 2019-03-27 18:27:40 UTC
Line 38 of /etc/cron.daily/update-spamassassin-rules:

systemctl try-restart amavisd

Whilst this will only restart the service if it's enabled, it does log an error if the amavisd unit file does not exist at all. Whilst there is no immediately obvious detrimental effect, the fact it causes cron to mail that to me every day for every install is a bit irritating :)

Failed to try-restart amavisd.service: Unit amavisd.service not found.
run-parts: /etc/cron.daily/update-spamassassin-rules exited with return code 5

One possibility would be to amend the line something like:

[ "active" = $(systemctl is-active amavisd) ] && systemctl restart amavisd

Which is silent in the event of the unit being missing.
Comment 1 Philippe Chaintreuil 2019-03-28 12:08:19 UTC
Seems more like we're after just if amavis is installed.  (Eg: what if it failed?  We'd probably want to still restart it.)

I'm still using OpenRC personally.  Mind sending me output from the following?

systemclt --full list-unit-files | egrep '(spamassassin|amavis)'

(Just looking to see what the spamassassin line looks like and make sure you don't have an amavis entry.)
Comment 2 Dan Goodliffe 2019-03-28 12:43:58 UTC
I've popped in the output of the other calls too so you can see my reasoning.
Specifically, is-active reports missing units as inactive.

defiant ~ $ systemctl --full list-unit-files | egrep '(spamassassin|amavis)'
spamassassin.service                   enabled        
defiant ~ $ systemctl is-active amavisd
inactive
defiant ~ $ systemctl is-active spamassassin
active
defiant ~ $
Comment 3 Michael Orlitzky gentoo-dev 2019-03-28 12:56:44 UTC
We don't want to do anything if amavisd isn't already running... some users might have it installed, even though they're not using it. And if the administrator has stopped amavis manually for some reason, we shouldn't surprise re-start it at midnight.

The "is-active" test sounds like it does that. After reading the systemctl man page, it looks to me like "try-reload-or-restart" might also be a tiny improvement, since it will reload amavis gracefully rather than doing a full stop/restart. Putting them together, we'd get something like

[ systemctl is-active --quiet amavisd ] && systemctl try-reload-or-restart amavisd

Does that work? I'm also still using OpenRC so can't really test.
Comment 4 Philippe Chaintreuil 2019-03-28 13:17:45 UTC
I guess I was more thinking along the lines of:

(systemclt --full list-unit-files | grep -q amavisd.service) && systemctl try-reload-or-restart amavisd

Before the && checks to see if it's installed.  After the &&, the try-*restart checks if it's been enabled.
Comment 5 Dan Goodliffe 2019-03-28 14:02:34 UTC
Drop the []s, this works me

systemctl is-active --quiet amavisd && systemctl try-reload-or-restart amavisd
Comment 6 Philippe Chaintreuil 2019-03-28 17:38:43 UTC
If we go the is-active route, the "try-" is redundant.

@mjo: Sounds like none of us are setup to test the opposite case (amavisd is installed and running), know of anyone who can test that case (short of me trying to build a fresh Gentoo VM) for this?
Comment 7 Dan Goodliffe 2019-03-28 18:25:00 UTC
I've installed amavisd-new-2.11.1-r3...

firebrand ~ # systemctl is-active amavisd
inactive
firebrand ~ # systemctl enable amavisd
Created symlink /etc/systemd/system/multi-user.target.wants/amavisd.service → /lib/systemd/system/amavisd.service.
firebrand ~ # systemctl is-active amavisd
inactive
firebrand ~ # systemctl start amavisd
firebrand ~ # systemctl is-active amavisd
failed
firebrand ~ # echo $?
3
firebrand ~ # systemctl is-active clamd
active
firebrand ~ # echo $?
0
firebrand ~ #

Without going into configuring it so it works... on the face of it, this approach should be fine. I don't know if a reload is sufficient to accomplish what it is intended from update-spamassassin-rules, given it's a restart now, maybe leave it as restart and just swap the try- for the is-active test?
Comment 8 Michael Orlitzky gentoo-dev 2019-03-28 18:40:10 UTC
(In reply to Philippe Chaintreuil from comment #6)
> If we go the is-active route, the "try-" is redundant.

Indeed, I wouldn't care either way if you wanted to drop it. My thinking was that it kept the two commands logically separate,

  * This is what we want to do: systemctl try-reload-or-restart amavisd
  * And this is just to keep it quiet: systemctl is-active --quiet amavisd

But I could be over-thinking this =)

As I mentioned, this scenario doesn't even affect me.


> @mjo: Sounds like none of us are setup to test the opposite case (amavisd is
> installed and running), know of anyone who can test that case (short of me
> trying to build a fresh Gentoo VM) for this?

I don't think you need to go that far. We have a user who can test it, and it will sit in ~arch for a while to iron out any problems.


>  I don't know if a reload is sufficient to accomplish what it is intended from update-spamassassin-rules, given it's a restart now, maybe leave it as restart and just swap the try- for the is-active test?

A reload does suffice -- that's what we do with OpenRC.
Comment 9 Larry the Git Cow gentoo-dev 2019-03-31 18:50:29 UTC
The bug has been closed via the following commit(s):

https://gitweb.gentoo.org/repo/gentoo.git/commit/?id=984199eccccd1fa7867c07f8a467d298eade11fa

commit 984199eccccd1fa7867c07f8a467d298eade11fa
Author:     Philippe Chaintreuil <gentoo_bugs_peep@parallaxshift.com>
AuthorDate: 2019-03-30 12:41:44 +0000
Commit:     Michael Orlitzky <mjo@gentoo.org>
CommitDate: 2019-03-31 18:46:19 +0000

    mail-filter/spamassassin: Suppress warning in cron in some setups
    
    Suppress warning in cron job when the script tries to restart amavisd
    on systemd systems where amavisd is not installed.
    
    Closes: https://bugs.gentoo.org/681872
    Closes: https://github.com/gentoo/gentoo/pull/11542
    Signed-off-by: Philippe Chaintreuil <gentoo_bugs_peep@parallaxshift.com>
    Package-Manager: Portage-2.3.62, Repoman-2.3.11
    Signed-off-by: Michael Orlitzky <mjo@gentoo.org>

 .../files/update-spamassassin-rules-r1.cron        |  41 +++
 .../spamassassin/spamassassin-3.4.2-r6.ebuild      | 286 +++++++++++++++++++++
 2 files changed, 327 insertions(+)
Comment 10 Steven Green 2023-11-22 10:01:54 UTC
Because bash scripts exit with the status of the last command. If systemctl is installed but amavisd is not active the script returns with the value 4.

This causes cron to send an email.

run-parts: /etc/cron.daily/update-spamassassin-rules exited with return code 4

Suggest replacing the chained command:

systemctl is-active --quiet amavisd \
            && systemctl try-reload-or-restart amavisd

which returns the value of systemctl is-active (which is 4 if amvsisd is not active), with an if which returns 0.

if systemctl is-active --quiet amavisd; then systemctl try-reload-or-restart amavisd; fi
Comment 11 Philippe Chaintreuil 2023-11-24 18:25:46 UTC
Added PR to switch from "&&" to "if".
Comment 12 Larry the Git Cow gentoo-dev 2024-01-27 08:50:07 UTC
The bug has been closed via the following commit(s):

https://gitweb.gentoo.org/repo/gentoo.git/commit/?id=8cbc788fa83b225e7fd72f38b248a50a1e21e616

commit 8cbc788fa83b225e7fd72f38b248a50a1e21e616
Author:     Philippe Chaintreuil <gentoo_bugs_peep@parallaxshift.com>
AuthorDate: 2023-11-24 18:19:30 +0000
Commit:     Joonas Niilola <juippis@gentoo.org>
CommitDate: 2024-01-27 08:48:55 +0000

    mail-filter/spamassassin: Fix script output when amavisd is disabled
    
    Because bash scripts exit with the status of the last command. If systemctl
    is installed but amavisd is not active the script returns with the value 4.
    
    This causes cron to send an email.
    
    Switching from "&&" to an if fixes this.
    
    Signed-off-by: Philippe Chaintreuil <gentoo_bugs_peep@parallaxshift.com>
    Closes: https://bugs.gentoo.org/681872
    Closes: https://github.com/gentoo/gentoo/pull/33969
    Signed-off-by: Joonas Niilola <juippis@gentoo.org>

 mail-filter/spamassassin/files/update-spamassassin-rules-r1.cron | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)