[systemd-devel] service dependencies

Markus Rathgeb maggu2810 at gmail.com
Tue Jan 10 11:47:33 UTC 2023


Hello,

I have a question about service dependencies.

Assume there are two services
* test1
* test2

(for testing purpose only I am using user services)

The test2 service requires that test1 service is active.
The test2 service cannot work if test1 is not active, so it should ensure
* test1 is started before test2
* test2 is terminated if test1 terminates

I tried this unit section for test2.service

BindsTo=test1.service
After=test1.service

(The point I do not understand is equal for `Requires` instead of `BindsTo`)

If I start test2.service test1 is started and afterwards test2.

systemctl --user start test2

Jan 10 11:46:59 tpt590 systemd[2552]: Started test1.service.
Jan 10 11:46:59 tpt590 systemd[2552]: Started test2.service.

If I stop test1.service teset2 is stopped, too.

systemctl --user stop test1

Jan 10 11:47:49 tpt590 systemd[2552]: Stopping test2.service...
Jan 10 11:47:49 tpt590 systemd[2552]: Stopped test2.service.
Jan 10 11:47:49 tpt590 systemd[2552]: Stopping test1.service...
Jan 10 11:47:49 tpt590 systemd[2552]: Stopped test1.service.

Then I start test1.service again

systemctl --user start test1

Jan 10 11:48:42 tpt590 systemd[2552]: Started test1.service.

What I do not understand is, why `test2.service` is not started again.
Or how can I ensure test2 is started again?

* test2 requires / binds to test1
* test2 has been started explicit
* test1 is started as a dependency
* the dependency test1 is stopped explicit
* I would assume the service manager still is aware of the explicit start
of test2 but stopped it because the requirements / dependencies does not
met.
* I would assume if test1 (the missing requirement / dependency) is started
again the service manager realize that now all dependencies are met and
test2 can be started again, too.

Why is this wrong?
How can I declare test2 unit section to ensure it works as expected by me?

Many thanks in advance,
Markus
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.freedesktop.org/archives/systemd-devel/attachments/20230110/46c9b006/attachment-0001.htm>


More information about the systemd-devel mailing list