[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: migration from cron.daily to systemd timers



On Tue, Jan 07, 2020 at 05:32:47PM -0600, Richard Laager wrote:
> Could you check for local modifications and only enable the timer if
> there were NOT local modifications?
> 
> [ -e /etc/default/spamassassin ] && . /etc/default/spamassassin
> if [ -d /run/systemd/system ] && [ "$CRON" = "1" ] &&
>    ! some_check_for_local_modifications
> then
>     systemctl enable spamassassin-daily-maintenance.timer
> fi

Since existing cron.daily scripts won't have any knowledge of the timer,
one possible transition process could involve having the installed cron
script unconditionally enable the timer when it runs.  Users who are
running with a modified script in place will continue to do so.  Users
who are running unmodified scripts, or who revert their system to the
original script during the package upgrade, will get the new behavior
which will perform the transition.

> If it was me, I'd just check for whether systemd is running (e.g. [ -d
> /run/systemd/system ]), not whether the timer unit is enabled. That way,
> at least moving forward, you're only supporting two scenarios (systemd
> uses the units, non-systemd uses cron) rather than three (those two plus
> the option of systemd systems still using cron).

My expectation is that there will be some systemd users who will still
prefer cron for some reason.  Those users could, obviously, just modify
the cron.daily script to remove the systemd conditional, but if we can
trivially support them, then I don't mind doing so.  On the other hand,
transitioning people to the timer wouldn't upset me at all either.

> If you were doing this new, I would suggest that you use cron.d instead
> of cron.daily. Then check for systemd by prefixing your command with:
>   [ -d /run/systemd/system ] || ...
> This way, if the user installs systemd-cron (which replaces crond and
> generates systemd service & timer units from cron files), it will not
> generate units for the cron job. See:
> https://github.com/systemd-cron/systemd-cron/blob/master/src/bin/systemd-crontab-generator.py#L335

I hadn't considered systemd-cron.  Thanks for pointing this out...

noah


Reply to: