Post by Andrei BorzenkovPost by Amit SahaPost by Amit SahaPost by Amit SahaHello,
I have a systemd service - drainconnections which I want to to make
sure
Post by Amit SahaPost by Amit SahaPost by Amit Sahafinishes stopping before systemd starts stopping another service. What
I
Post by Amit SahaPost by Amit SahaPost by Amit Sahaalso want is to if I stop supervisord service, drainconnections should
be
Post by Amit SahaPost by Amit SahaPost by Amit Sahastopped first.
It seems like BindsTo is what I need for establishing the coupling
between
If your description of services relationship is accurate and complete,
BindsTo is too strong here; you really need just PartsOf.
Thanks. PartOf looks like something more suitable. Would having PartOf in
supervisord obey the before after relationship setup by drainconnections
service?
PartsOf (like BindsTo) is orthogonal to After/Before. PartsOf/BindsTo
define what to do, After/Before define when to do.
Post by Amit SahaI will give it a shot.
Thanks. Tried it and that is how it works.
Post by Andrei BorzenkovPost by Amit SahaPost by Amit SahaPost by Amit Saha[Unit]
Description=Drain Connections
After=supervisord.service
BindsTo=supervisord.service
...
Post by Amit SahaPost by Amit SahaPost by Amit SahaIn addition, I also needed to add BindsTo=drainconnections to the
supervisord service.
This will create dependency loop with your unit definition shown above.
Wouldnât the Before/After take care of breaking the dependency loop? That
seems to be what I observed.
Probably I had to elaborate. If you need full BindsTo semantic (which is
superset of Requires) it only works as documented if you also have
corresponding After/Before which creates loop. Otherwise Requires part
is mostly useless. If you are only interested in propagating stop
request and "stopping on surprise removal" part of BindsTo then this is
probably OK, but this will make your units definitions rather confusing.
Thanks, I think your suggestion of using PartOf is more suitable for my use
case here - which is basically making sure that I can do some work before
systemd shuts down the system (killing supervisord) and use After/Before to
ensure the when.
This is my current unit file:
[Unit]
Description=Drain Connections
After=supervisord.service
PartOf=supervisord.service
[Service]
Type=oneshot
RemainAfterExit=True
ExecStart=/bin/true
ExecStop=/usr/bin/touch /var/shuttingdown1
ExecStop=/usr/bin/sleep 60
ExecStop=/usr/bin/touch /var/shuttingdown2
[Install]
WantedBy=multi-user.target
It looks like I added the BindsTo=drainconnectins.service to supervisord as
well for a use case where during shutdown, if supervisord was stopped
first, it would first stop drainconnections.service. But I don't need that
- since systemd figures out it needs to first stop drainconnections.service
before it stops supervisord.
I think the only change I would make to the supervisord configuration is so
that it always starts drainconnections.service when it's started.