Re: service dependencies

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Tue, Jan 10, 2023 at 2:48 PM Markus Rathgeb <maggu2810@xxxxxxxxx> wrote:
>
> 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.

Because nothing tells systemd to start test2.service when
test1.service is (requested to be) started.

> Or how can I ensure test2 is started again?
>

Using Wants=test2.service in test1.service should work.

> * 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



[Index of Archives]     [LARTC]     [Bugtraq]     [Yosemite Forum]     [Photo]

  Powered by Linux