I have a bunch of services (say S1, S2,... S10) that should only start after a critical service C1 has been initialized. C1 writes a file (say to /var/run/critical.init) indicating that it has completed its initialization. At this point, each of the services S1..S10 should be started by systemd.
While trying to implement the above, I used systemd's .path based activation and created two files: one for S1's .path file:
$ cat s1.path
[Path]
PathExists=/var/run/critical.init
Unit=s1.service
[Install]
WantedBy=multi-user.target
$ systemctl enable s1.path
and a file that describes the service itself:
$ cat s1.service
[Unit]
Description=Some service
After=syslog.target
[Service]
ExecStart=/usr/bin/s1
Type=simple
Restart=always
RestartSec=10
[Install]
WantedBy=multi-user.target
After a reboot, I verified that systemctl status s1 shows that the unit is active and S1 is not listed in the output of ps -ef (as expected). Soon after I create the file /var/run/critical.init by hand, systemd starts the unit s1.
The above experiment confirmed to me that path-based activation works for one unit. I would now like to extend this to all services S1...S10.
The obvious way is to write one .path file for each service, but I'm looking for a more elegant solution.
Can this problem be solved using a systemd target? If each of the services S1...S10 is made part of a new critical.target instead of the multi-user.target, can I set the dependency for /var/log/critical.init to be present before any of the units in critical.target is fired? Any other suggestions are welcome too.