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

Re: Q: systemd-timer vs cron




Am 12.03.22 um 08:09 schrieb Andreas Metzler:
On 2022-03-12 Hideki Yamane <henrich@iijmio-mail.jp> wrote:
  Is there any suggestion or guideline for pacakges that contain
  both systemd-timer unit setting and cronjob? Don't they conflict
  or not

Hello,

You want to skip running the cronjob on systems with systemd as init
systems. e.g. exim's daily cronjob works like this:
1. the systemd unit runs /etc/cron.daily/exim4-base with argument
    systemd-timer.
2. /etc/cron.daily/exim4-base checks for a systemd setup by testing
    existence of /run/systemd/system. On a systemd setup the script
    exits immediately when executed from cron (i.e. $1!=systemd-timer).


I would consider this an anti-pattern.
If you have such a complex cron-daily script, I'd factor that out into a script in /usr/lib/foo and call that directly from both the cron entry and the systemd timer.

It's the same kind of anti pattern like creating a .service unit containing
ExecStart=/etc/init.d/foo systemd

Please don't do that.
If you actually have a need to call complex shell machinery to run your daemon, please factor this out into an independent script and call it from either the sysv init script or the systemd service file.

systemd services should not depend on SysV init scripts and systemd timers should not depend on cron files.

Attachment: OpenPGP_signature
Description: OpenPGP digital signature


Reply to: