[systemd-devel] [PATCH 2/2] Libcgroup: added cgconfig.service unit for systemd.

Lennart Poettering lennart at poettering.net
Tue Dec 13 04:31:24 PST 2011


On Tue, 13.12.11 13:06, Jan Safranek (jsafrane at redhat.com) wrote:

> 
> On 12/13/2011 12:46 PM, Lennart Poettering wrote:
> > On Fri, 09.12.11 15:32, Jan Safranek (jsafrane at redhat.com) wrote:
> 
> <snip>
> 
> > Note that this will set up the cgroup structure only during late boot,
> > which should be fine for most cases. However, in some cases it might
> > make sense to initialize this due to early boot (for example, to handle
> > early-boot service, like udev).if you care for those add lines like
> > the following:
> > 
> > DefaultDependencies=no
> > Conflicts=shutdown.target
> > Before=basic.target shutdown.target
> 
> I expect that the services that needs cgroups would have
> "After=cgconfig.service" and systemd will start cgconfig before any of
> them, regardless how early in the boot it is. In the end I might not
> need any After/Before in cgconfig.conf at all. Of course, admin must add
> this "After=cgconfig.service" manually to all dependent services, but he
> already needs to add "ControlGroup=..." there.

Well, this is mostly what happens, except that early boot services are
a bit special. 

i.e. normal services are implicitly ordered after basic.target. An early
boot service is not, and even usually ordered before
basic.target. Therefore, if your service cgconfig.service is not marked
as early boot service it will be ordered after basic.target, and hence
we'd have an ordering loop against an early boot service, if it wants to
be started after cgconfig.service...

But maybe it's not worth thinking about this too much, since early boot
services are special anyway, and we can still think about this if
there's actaully somebody who wants to move an early boot service into
an arbitrary cgroup.

> I would end up with this simple service in the end:
> 
> [Unit]
> DefaultDependencies=no
> 
> [Service]
> Type=oneshot
> RemainAfterExit=yes
> ExecStart=/sbin/cgconfigparser -l /etc/cgconfig.conf -s 1664
> ExecStop=/sbin/cgclear -l /etc/cgconfig.conf -e
> 
> [Install]
> WantedBy=sysinit.target
> 
> Could this work?

I'd recommend adding this too:

Conflicts=shutdown.target
Before=basic.target shutdown.target

Otherwise we'd not invoke the stop binary on shutdown. And the
Before=basic.target ensures that the cgroup tree is fully set up before
normal services are started, which might not be necessary, but might
still make sense?

Lennart

-- 
Lennart Poettering - Red Hat, Inc.


More information about the systemd-devel mailing list