-1

I have three tasks that are currently being run daily by cron, one after the next, as follows:

gatekeeper ~ # ls -l /etc/cron.daily/
total 92
-rwxr-xr-x  1 root root 3814 May 10  2019 1task-A.sh
-rwxr-xr-x  1 root root 1406 Jun 28  2015 2task-B.sh
-rwxr-xr-x  1 root root 1414 May 10  2019 3task-C.sh

I need to replicate this using systemd.

I know I can create three oneshot systemd services, controlled by three systemd timer files, however this will cause the three tasks to run independently of one another, in parallel, and out of order.

What modification do I make to the systemd service file or timer file to indicate that the three tasks, when executed, must run consecutively (not in parallel) and in order (not at random).

Graham Leggett
  • 911
  • 7
  • 20
  • I’m voting to close this question because From the tag: systemd questions should be for *programming questions* using systemd or its libraries. Questions about *configuring the daemon* (including writing unit files) are better directed to Unix & Linux: https://unix.stackexchange.com. Please delete this. – Rob May 24 '23 at 07:05

1 Answers1

0

Try having only 1 timer unit and 3 services. Then, set the services Types= to oneshot. By setting After= and Wants= properties between the services, you should be able to run the 3 services sequentially when the timer is triggered.

Have a look at this post: https://serverfault.com/questions/900779/systemd-setting-dependencies-between-templated-timer-units

task-C.timer:

[Unit]
Description=daily task

[Timer]
OnCalendar=daily
Unit=task-C.service

[Install]
WantedBy=timers.target

task-C.service:

[Unit]
Description=task C
Wants=task-B.service
After=task-B.service

[Timer]
ExecStart=/usr/bin/task-C.sh
Type=oneshot

[Install]
WantedBy=timers.target
deribaucourt
  • 424
  • 8