1

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.

  • 1
    Note that systemd has a whole mechanism of its own where services can announce that they are ready and that dependent services can now be started, no flag files or path units required. This question is based upon the assumption that path units and flag files are the way to do this. How do I arrange for services S0, S1, and S2 not to start until service C has finished initializing and become ready? is a different, and better, question. – JdeBP Dec 20 '16 at 1:25
  • Hello JdeBP, you are right - my question was based on the understanding that a path unit is needed to achieve such synchronization b/w units. Can you please post any tips/examples on how I can get this done without path units and files? – linuxfan Dec 20 '16 at 3:02
  • 1
  • I read through the link you posted. Taking the approach with notify_systemd() requires me to modify each of my services (and not all of them are written in C) to achieve synchronization. I am hoping that it can be achieved with using only systemd's features. – linuxfan Dec 20 '16 at 17:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.