I have two service oneshots:
- one that creates snapshots
- one that sends snapshots
The second one (send) should always be executed after the first one (create) is finished. Currently the services, which are of type oneshot, run at the same time.
The services are defined as follows (the exact used command from the following examples doesn't matter for this question, detailed requirements below the examples):
- Service to create snapshots (
pyznap.service):[Unit] Description=Create ZFS snapshots Documentation=man:pyznap(1) Requires=local-fs.target After=local-fs.target [Service] Type=oneshot ExecStart=/usr/bin/pyznap snap - Service to send snapshots (
pyznap-send.service):[Unit] Description=Send ZFS snapshots Documentation=man:pyznap(1) Requires=local-fs.target network-online.target After=local-fs.target network-online.target pyznap.service [Service] Type=oneshot ExecStart=/usr/bin/pyznap send
Currently, they are triggered by individual (and independent) timers:
- The timer for the create snapshot (
pyznap.timer):[Unit] Description=Run pyznap snap every 15 minutes [Timer] OnCalendar=*:0/15 Persistent=true [Install] WantedBy=timers.target - The timer for the send snapshot (
pyznap-send.timer):[Unit] Description=Run pyznap send every 15 minutes [Timer] OnCalendar=*:0/15 Persistent=true [Install] WantedBy=timers.target
Additional notes:
- The question is related to "How do you configure multiple systemd services to use one timer?, but this solution still runs the services at the same time
- As per
systemddesign, only one service can be referenced byTimer.Unit. - The units are separated due to different requirements:
- only the "send" service needs network
- the "create" service must run also without network
- I am fine with skipping those services if requirements are not met
- The "send" service should run immediately after the previous "create" service.
- If there's only one timer:
- the timer cannot activate only the send snapshot service as the create snapshot service needs also to run without network
- but the timer could activate only the create snapshot service if there's a way to run the send snapshot service directly afterwards
- We don't know how long the first create snapshot service takes.