[systemd-devel] Waiting for nspawn services

Zbigniew Jędrzejewski-Szmek zbyszek at in.waw.pl
Sat Oct 25 08:50:05 PDT 2014


On Sat, Oct 25, 2014 at 05:39:51AM -0400, Rich Freeman wrote:
> One of the useful options in nspawn is the ability to boot the init
> within the container using -b, especially if that init happens to be
> systemd.
> 
> However, I could not find any easy way to set a dependency on a
> service within a container.
> 
> Example use case:
> Unit 1 boots an nspawn container that runs mysql
> Unit 2 launches a service that depends on mysql, or it might even be
> another container that depends on mysql.
> 
> I could put together a script that pings mysql until it is up, but the
> original mysql unit already has to make the determination as to
> whether the service is ready, so this is redundant.  Also, that is a
> solution specific to a single daemon, while the problem is generic.
> 
> I could think of a few possible ways to solve this.
> 
> 1.  Have a way to actually specify a dependency on a unit within a container.
> 2.  Have a generic wait program that can wait for any unit to start
> within a container, or perhaps even on a remote host.
> 3.  Have a way for nspawn to delay becoming online until all services
> inside have become online.
That would be nice functionality. I don't think anything like this exists
currently, but systemd can send sd_notify() messages when it receives
appropriate env. variables (it does that already for user sessions),
and systemd-nspawn could be hooked to pass them.

You could also:
4. Use socket activation for the whole container. If this is possible (i.e.
   all services inside of the container can be socket activated) then this
   is probably the best option.

> Actually, being able to express unit dependencies across machines
> might be useful on many levels, but I'll be happy enough just to be
> able to handle containers on a single host for now.

Zbyszek


More information about the systemd-devel mailing list