26.07.2025 22:31, Kevin P. Fleming wrote:
On Sat, Jul 26, 2025, at 13:07, Maximilian Bosch wrote:
Now, my plan is to actually contribute a fix for this, but upon starting
I realized, that I need some pointers:
* This seems like a little bit of a special case: you need bidirectional
dependencies and at least one unit involved needs `BindsTo`. Does it make
sense to add as another paragraph to `systemd.unit(5)`? Is there a
better-suited place for this? Or even a reason that speaks for the
status-quo, i.e. not documenting potential implementation details?
* Am I on the right track with my observations? As mentioned above,
I noticed today that this is reliably reproducible on an idle VM, but
not on my workstation.
I've struggled with something very similar. I've got PostgreSQL and a number of
services which depend on it. I want:
* Services to not start until PostgreSQL is available (not just 'start job'
queued).
After=postgresql.service
This depends on PostgreSQL service definition - whether "ExecStart
completed" can be considered equal to "PostgreSQL is available".
And yes, it leaves out the question how these services are started in
the first place.
* Services to automatically stop before PostgreSQL if a 'stop job' for
PostgreSQL is queued.
> * Services to automatically stop before PostgreSQL, and automatically
start after it is available, if a 'restart job' for PostgresSQL is
queued and completes.>
PartOf=postgresql.service
After=postgresql.service
For both stop and restart.
* Services to automatically start after PostgreSQL is available if they were
running when a 'stop job' for PostgreSQL completed and then a 'start job' also
completes.
I do not think it is possible and I believe it was discussed and there
is an issue for it. This requires memory of the past and systemd does
not have it. It is also unclear how to implement it at all.
Basically it contradicts the previous requirement (service should stop
it PostgreSQL is stopped). You want computer to read your mind - "I want
this service to be stopped except when I want it to be started again".
You can add
WantedBy=postgresql.service
and this will start all dependent services. Of course, it will do it
also if they were not started before by some other means.
In essence I want to ensure that the services get restarted if PostgreSQL gets
restarted for any reason, including package upgrades. Some of them can tolerate
the database restarting themselves, but others cannot, and in any case they
can't do anything useful if they are running while the database is unavailable.
I don't know of a practical way to construct unit dependencies today which can
achieve this.