<div dir="ltr"><br><br><div class="gmail_quote"><div dir="ltr">On Sun, Jan 28, 2018 at 5:04 PM Andrei Borzenkov <<a href="mailto:arvidjaar@gmail.com">arvidjaar@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">28.01.2018 02:11, Amit Saha пишет:<br>
> On Sun, 28 Jan 2018 at 6:22 am, Andrei Borzenkov <<a href="mailto:arvidjaar@gmail.com" target="_blank">arvidjaar@gmail.com</a>><br>
> wrote:<br>
><br>
>> 26.01.2018 05:11, Amit Saha пишет:<br>
>>> Hello,<br>
>>><br>
>>> I have a systemd service - drainconnections which I want to to make sure<br>
>>> finishes stopping before systemd starts stopping another service. What I<br>
>>> also want is to if I stop supervisord service, drainconnections should be<br>
>>> stopped first.<br>
>>><br>
>>> It seems like BindsTo is what I need for establishing the coupling<br>
>> between<br>
>>> the two units.<br>
>><br>
>> If your description of services relationship is accurate and complete,<br>
>> BindsTo is too strong here; you really need just PartsOf.<br>
><br>
><br>
> Thanks. PartOf looks like something more suitable. Would having PartOf in<br>
> supervisord obey the before after relationship setup by drainconnections<br>
> service?<br>
><br>
<br>
PartsOf (like BindsTo) is orthogonal to After/Before. PartsOf/BindsTo<br>
define what to do, After/Before define when to do.<br>
<br>
> I will give it a shot.<br></blockquote><div><br></div><div>Thanks. Tried it and that is how it works.</div><div><br></div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
><br>
>><br>
>><br>
>>> The following unit file describes drainconnections:<br>
>>><br>
>>><br>
>>> [Unit]<br>
>>> Description=Drain Connections<br>
>>> After=supervisord.service<br>
>>> BindsTo=supervisord.service<br>
>>><br>
...<br>
>>><br>
>>> In addition, I also needed to add BindsTo=drainconnections to the<br>
>>> supervisord service.<br>
>>><br>
>><br>
>> This will create dependency loop with your unit definition shown above.<br>
><br>
><br>
> Wouldn’t the Before/After take care of breaking the dependency loop? That<br>
> seems to be what I observed.<br>
><br>
<br>
Probably I had to elaborate. If you need full BindsTo semantic (which is<br>
superset of Requires) it only works as documented if you also have<br>
corresponding After/Before which creates loop. Otherwise Requires part<br>
is mostly useless. If you are only interested in propagating stop<br>
request and "stopping on surprise removal" part of BindsTo then this is<br>
probably OK, but this will make your units definitions rather confusing.<br></blockquote><div><br></div><div>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.</div><div><br></div><div>This is my current unit file:</div><div><br></div><div><div>[Unit]</div><div>Description=Drain Connections</div><div>After=supervisord.service</div><div>PartOf=supervisord.service</div><div><br></div><div>[Service]</div><div>Type=oneshot</div><div>RemainAfterExit=True</div><div>ExecStart=/bin/true</div><div>ExecStop=/usr/bin/touch /var/shuttingdown1</div><div>ExecStop=/usr/bin/sleep 60</div><div>ExecStop=/usr/bin/touch /var/shuttingdown2</div><div><br></div><div>[Install]</div><div>WantedBy=multi-user.target</div><div><br></div></div><div><br></div><div>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.</div><div><br></div><div>I think the only change I would make to the supervisord configuration is so that it always starts drainconnections.service when it's started.</div><div><br></div></div></div>