You are not logged in.
Hi all,
I want to implement three systemd units, that depend on each other in a specific way:
1) A mount unit, mounting (on start) and unmounting (on stop) a tmpfs.
2) A unit, running as root, extracting (on start) and re-packing (on stop) a tar archive.
3) A "main" unit run as a specific user operating on the archive content.
The dependency is as follows:
Unit #3 should be the only one having an install section and be directly handled by the sysadmin.
Desired dependency order:
When unit #3 is started, it shall first start unit #1, then unit #2, then itself.
When unit #3 is sopped, it shall first stop itself, then unit #2, then unit #1.
I tinkered with different systemd dependency settings including BindsTo and PartOf but either the startup or the shutdown sequence will not be in the desired order.
How can I implement the aforementioned dependecy order and is this even possible through "plain" systemd units?
Solution
I managed to implement this using systemd.targets.
Last edited by schard (2020-10-13 08:59:19)
Inofficial first vice president of the Rust Evangelism Strike Force
Offline
Typically use a .target to encapsulate the other services. This can have the .install section. Use 'After=' and 'Before=' to order the other services
However, in this case, it seems like one service could work:
1. RequiresMountsFor=/path/to/tmpfs (this will also require a .mount file for the tmpfs location...unless systemd has a special tmpfs command...)
2. ExecStartPre=<extract archive>
3. ExecStart=work on archive
4. ExecStartPost=<repack archive>
Offline
@firecat53
Thanks for the suggestion to use a target. I will try this later on.
Also the single unit solution sounds interesting. Will try that, too.
Inofficial first vice president of the Rust Evangelism Strike Force
Offline