[systemd-devel] Implicit unit dependency on slice might be too weak ?

Francis Moreau francis.moro at gmail.com
Tue Sep 22 06:39:49 PDT 2015


On Tue, Sep 22, 2015 at 2:18 PM, Zbigniew Jędrzejewski-Szmek
<zbyszek at in.waw.pl> wrote:
> On Tue, Sep 22, 2015 at 11:52:05AM +0200, Francis Moreau wrote:
>> On Tue, Sep 22, 2015 at 11:14 AM, David Herrmann <dh.herrmann at gmail.com> wrote:
>> > Hi
>> >
>> > On Tue, Sep 22, 2015 at 10:58 AM, Francis Moreau <francis.moro at gmail.com> wrote:
>> [...]
>> >>>
>> >>
>> >> But what if the slice fails to start ?
>> >>
>> >> Will the unit asking for a specific slice (which fails to start) be
>> >> moved into another slice ? It seems that whatever the final
>> >> destination used by systemd, the constraints used by the "fallback"
>> >> slice won't be correct, no ?
>> >
>> > Correct.
>> >
>> > You still get a big fat error on your screen and you should fix your
>> > setup. Again, if that's no suitable, you better use "Requires=".
>> >
>>
>> To put a unit in a slice, one uses by default
>>
>>    Slice=myslice.slice
>>
>> and the default behaviour is to add Wants=myslice.slice to the unit.
>>
>> If the unit will always fail to start if myslice.slice fails then I
>> would say the default  behaviour should be Requires=myslice.slice.
>
> Does it actually fail? If yes, then Requires= would be better. If not,
> then Wants= should stay.
>

Well that simply means Requires= is more appropriate IMHO.

> (I tried to test this:
> - with a slice with ConditionPathExists= that is false, the
>   slice is not started and the unit is started.

The strange thing is that even if the condition is not met, the slice
is created in the cgroupfs and is used:

# cat >myservice.service<<EOF
[Unit]
Description=A testing unit

[Service]
Slice=myslice.slice
ExecStart=/usr/bin/sh -c 'sleep 1000'
EOF

# cat >myslice.slice<<EOF
[Unit]
Before=slices.target
ConditionPathExists=/foo/bar

[Slice]
MemoryLimit=66M
EOF

# systemctl daemon-reload

# systemctl start myservice.service

# systemctl status myslice.slice
● myslice.slice
   Loaded: loaded (/run/systemd/system/myslice.slice; static; vendor
preset: disabled)
   Active: inactive (dead)
Condition: start condition failed at Tue 2015-09-22 15:26:03 CEST; 3s ago
           ConditionPathExists=/foo/bar was not met
   Memory: 456.0K (limit: 66.0M)
   CGroup: /myslice.slice
           └─myservice.service
             └─930 sleep 1000

# find /sys/fs/cgroup/ -name mys\*
/sys/fs/cgroup/devices/myslice.slice
/sys/fs/cgroup/memory/myslice.slice
/sys/fs/cgroup/systemd/myslice.slice
/sys/fs/cgroup/systemd/myslice.slice/myservice.service

# cat /sys/fs/cgroup/memory/myslice.slice/memory.limit_in_bytes
69206016

# pacman -Q systemd
systemd 226-1

So even if the condition is not met, the slice is created in
/sys/fs/cgroup and the unit is moved into it. But still systemd thinks
that the slice unit is dead...

And even if the slice is in a dead state and the condition is not met,
the unit is using it...

This seems to me a good example as for why to use Requires= by default.

Thanks.
-- 
Francis


More information about the systemd-devel mailing list