Say I have two packages, A
and B
, that offer a service each, a
and b
.
b
depends on a
. In other words, if service a
is currently active (running), then I can start and stop b
no problem. However, if a
is not active, b
should not start, at least not without first trying to start a
. Similarly, if I want to stop a
, then I expect b
to be taken down first, then a
. This all works great with systemd
.
I applied a fix to package A
.
What is the proper behavior of the package when I run dpkg --install A
?
It seems pretty evident that A
may know nothing of B
. So, if the prerm
script of A
runs:
systemctl stop a
It will take b
down along with it.
Then the new version of A
gets installed and in the postinst
I restart a
with:
systemctl start a
Is that the expected procedure to upgrade a package such as A
? Will systemd
somehow always remember to restart b
automatically? What if I had many more dependencies?
In systemd, the
systemctl restart
operation has a special behavior as compared to a pair of stop+start:systemctl restart a
— stop b, stop a, start a, start b (i. e. restarts dependent units, all in correct order)systemctl stop a && systemctl start a
— stop b, stop a, start a (i. e. does not remember about the dependent units)Note that this only happens when b.service has
Requires=a.service
. Wants=, After= and Before= do not enable this special behavior (butAfter=a.service
is most likely needed as well to order stops and starts against each other).So, to make this work, you probably need to run nothing from A's prerm script and
systemctl restart
from A's postrm script if their first argument isupgrade
, and normalsystemctl stop
+systemctl start
otherwise. (Note: I may be wrong here — not a Debian user/maintainer),