Re: [systemd-devel] Behavior of BindsTo when stopping a service

2018-01-28 Thread Amit Saha
On Sun, Jan 28, 2018 at 5:04 PM Andrei Borzenkov 
wrote:

> 28.01.2018 02:11, Amit Saha пишет:
> > On Sun, 28 Jan 2018 at 6:22 am, Andrei Borzenkov 
> > wrote:
> >
> >> 26.01.2018 05:11, Amit Saha пишет:
> >>> Hello,
> >>>
> >>> I have a systemd service - drainconnections which I want to to make
> sure
> >>> finishes stopping before systemd starts stopping another service. What
> I
> >>> also want is to if I stop supervisord service, drainconnections should
> be
> >>> stopped first.
> >>>
> >>> It seems like BindsTo is what I need for establishing the coupling
> >> between
> >>> the two units.
> >>
> >> 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.
>
> > I will give it a shot.
>

Thanks. Tried it and that is how it works.



> >
> >>
> >>
> >>> The following unit file describes drainconnections:
> >>>
> >>>
> >>> [Unit]
> >>> Description=Drain Connections
> >>> After=supervisord.service
> >>> BindsTo=supervisord.service
> >>>
> ...
> >>>
> >>> In 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.
___
systemd-devel mailing list
systemd-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/systemd-devel


Re: [systemd-devel] Behavior of BindsTo when stopping a service

2018-01-27 Thread Andrei Borzenkov
28.01.2018 02:11, Amit Saha пишет:
> On Sun, 28 Jan 2018 at 6:22 am, Andrei Borzenkov 
> wrote:
> 
>> 26.01.2018 05:11, Amit Saha пишет:
>>> Hello,
>>>
>>> I have a systemd service - drainconnections which I want to to make sure
>>> finishes stopping before systemd starts stopping another service. What I
>>> also want is to if I stop supervisord service, drainconnections should be
>>> stopped first.
>>>
>>> It seems like BindsTo is what I need for establishing the coupling
>> between
>>> the two units.
>>
>> 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.

> I will give it a shot.
> 
>>
>>
>>> The following unit file describes drainconnections:
>>>
>>>
>>> [Unit]
>>> Description=Drain Connections
>>> After=supervisord.service
>>> BindsTo=supervisord.service
>>>
...
>>>
>>> In 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.

___
systemd-devel mailing list
systemd-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/systemd-devel


Re: [systemd-devel] Behavior of BindsTo when stopping a service

2018-01-27 Thread Amit Saha
On Sun, 28 Jan 2018 at 6:22 am, Andrei Borzenkov 
wrote:

> 26.01.2018 05:11, Amit Saha пишет:
> > Hello,
> >
> > I have a systemd service - drainconnections which I want to to make sure
> > finishes stopping before systemd starts stopping another service. What I
> > also want is to if I stop supervisord service, drainconnections should be
> > stopped first.
> >
> > It seems like BindsTo is what I need for establishing the coupling
> between
> > the two units.
>
> 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?

I will give it a shot.

>
>
> > The following unit file describes drainconnections:
> >
> >
> > [Unit]
> > Description=Drain Connections
> > After=supervisord.service
> > BindsTo=supervisord.service
> >
> > [Service]
> > Type=oneshot
> > RemainAfterExit=True
> > ExecStart=/bin/true
>
> I think recent sytsemd relaxes requirement, so you can omit ExecStart here.


Thanks.

>
>
> > ExecStop=/usr/bin/touch /var/shuttingdown1
> > ExecStop=/usr/bin/sleep 60
> > ExecStop=/usr/bin/touch /var/shuttingdown2
> >
> > [Install]
> > WantedBy=multi-user.target
> >
> >
> > In 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.



>
> > Things work as desired for me considering the above configuration.
> >
> > Am I on the right track here? Thanks in advance.
> >
> > Best Wishes,
> > Amit.
> >
> >
> >
> > ___
> > systemd-devel mailing list
> > systemd-devel@lists.freedesktop.org
> > https://lists.freedesktop.org/mailman/listinfo/systemd-devel
> >
>
>
___
systemd-devel mailing list
systemd-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/systemd-devel


Re: [systemd-devel] Behavior of BindsTo when stopping a service

2018-01-27 Thread Andrei Borzenkov
26.01.2018 05:11, Amit Saha пишет:
> Hello,
> 
> I have a systemd service - drainconnections which I want to to make sure
> finishes stopping before systemd starts stopping another service. What I
> also want is to if I stop supervisord service, drainconnections should be
> stopped first.
> 
> It seems like BindsTo is what I need for establishing the coupling between
> the two units.

If your description of services relationship is accurate and complete,
BindsTo is too strong here; you really need just PartsOf.

> The following unit file describes drainconnections:
> 
> 
> [Unit]
> Description=Drain Connections
> After=supervisord.service
> BindsTo=supervisord.service
> 
> [Service]
> Type=oneshot
> RemainAfterExit=True
> ExecStart=/bin/true

I think recent sytsemd relaxes requirement, so you can omit ExecStart here.

> ExecStop=/usr/bin/touch /var/shuttingdown1
> ExecStop=/usr/bin/sleep 60
> ExecStop=/usr/bin/touch /var/shuttingdown2
> 
> [Install]
> WantedBy=multi-user.target
> 
> 
> In addition, I also needed to add BindsTo=drainconnections to the
> supervisord service.
> 

This will create dependency loop with your unit definition shown above.

> Things work as desired for me considering the above configuration.
> 
> Am I on the right track here? Thanks in advance.
> 
> Best Wishes,
> Amit.
> 
> 
> 
> ___
> systemd-devel mailing list
> systemd-devel@lists.freedesktop.org
> https://lists.freedesktop.org/mailman/listinfo/systemd-devel
> 

___
systemd-devel mailing list
systemd-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/systemd-devel


[systemd-devel] Behavior of BindsTo when stopping a service

2018-01-25 Thread Amit Saha
Hello,

I have a systemd service - drainconnections which I want to to make sure
finishes stopping before systemd starts stopping another service. What I
also want is to if I stop supervisord service, drainconnections should be
stopped first.

It seems like BindsTo is what I need for establishing the coupling between
the two units. The following unit file describes drainconnections:


[Unit]
Description=Drain Connections
After=supervisord.service
BindsTo=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


In addition, I also needed to add BindsTo=drainconnections to the
supervisord service.

Things work as desired for me considering the above configuration.

Am I on the right track here? Thanks in advance.

Best Wishes,
Amit.
___
systemd-devel mailing list
systemd-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/systemd-devel