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

Bug#923014: Add systemd unit - allow usage without cron installed



On Fri, 2022-11-18 at 16:06 +0100, Bill Allombert wrote:

> But then the user would not be able to configure it anymore,
> so I do not see the upside.

I just discovered an alternative that preserves the current location
and the conffile status of the cron.daily script. The script stays the
same, except it exits under systemd when the first argument isn't a
option indicating that the script should continue under systemd.
The systemd service then passes that option as the only parameter.

An example from the exim4-base package:

   $ head -n8 /etc/cron.daily/exim4-base
   #!/bin/sh
   
   EX4SYSTEMDTIMER=$1
   
   # skip in favour of systemd timer if called from cron.daily
   if [ -d /run/systemd/system ] && [ "$EX4SYSTEMDTIMER" != "systemd-timer" ]; then
               exit 0
   fi
   
   $ systemctl cat exim4-base.service exim4-base.timer
   # /lib/systemd/system/exim4-base.service
   [Unit]
   Description=exim4-base housekeeping
   Documentation=man:exim4(8)
   ConditionACPower=true
   Before=logrotate.service
   
   [Service]
   Type=oneshot
   ExecStart=/etc/cron.daily/exim4-base systemd-timer
   
   # performance options
   Nice=19
   IOSchedulingClass=best-effort
   IOSchedulingPriority=7
   
   # /lib/systemd/system/exim4-base.timer
   [Unit]
   Description=Daily exim4-base housekeeping
   Documentation=man:exim4(8)
   Before=logrotate.timer
   
   [Timer]
   OnCalendar=daily
   AccuracySec=12h
   Persistent=true
   
   [Install]
   WantedBy=timers.target

-- 
bye,
pabs

https://wiki.debian.org/PaulWise

Attachment: signature.asc
Description: This is a digitally signed message part


Reply to: