[lxc-devel] [PATCH] lxc-debian: support systemd as PID 1

Michael H. Warfield mhw at WittsEnd.com
Fri Nov 21 22:24:19 UTC 2014


On Fri, 2014-11-21 at 04:41 +0000, Serge Hallyn wrote:
> Quoting Antonio Terceiro (terceiro at debian.org):
> > Containers with systemd need a somewhat special setup, which I borrowed
> > and adaptec from lxc-fedora. These changes are required so that Debian 8
> > (jessie) containers work properly, and are a no-op for previous Debian
> > versions.
> > 
> > Signed-off-by: Antonio Terceiro <terceiro at debian.org>

> Michael and/or Stéphane may have other comments , but as you say this
> will not regress non-systemd hosts so looks like a step in the right
> direction to me, thanks.

While I did add code to the config.c file to detect systemd as the init
system and default it to enabling autodev, I would recommend adding
"lxc.autodev = 1" to containers generated by the template that are known
to be using systemd.  It can't go into the common config files because
of variability in distro revs and systemd utilization and still leaves
open the problem when a container is upgraded to a systemd release from
a non-systemd release, but that's what the runtime code is there for.

There's also the problem with lxc.kmsg and systemd-journald which, I
guess, doesn't impact this case because Debian is using systemd but not
journald?  I haven't confirmed that but noticed it in some articles.  If
journald is being used, you have to set "lxc.kmsg = 0" or journald will
end up in a messaging echo loop between /dev/console and /dev/kmsg.

Regards,
Mike

> Acked-by: Serge E. Hallyn <serge.hallyn at ubuntu.com>
> 
> > ---
> >  templates/lxc-debian.in | 30 ++++++++++++++++++++++++++++++
> >  1 file changed, 30 insertions(+)
> > 
> > diff --git a/templates/lxc-debian.in b/templates/lxc-debian.in
> > index 5ffbe21..6864a98 100644
> > --- a/templates/lxc-debian.in
> > +++ b/templates/lxc-debian.in
> > @@ -183,6 +183,34 @@ install_packages()
> >      fi
> >  }
> >  
> > +configure_debian_systemd()
> > +{
> > +    rootfs=$1
> > +    init="$(chroot ${rootfs} dpkg-query --search /sbin/init | cut -d : -f 1)"
> > +    if [ "$init" != "systemd-sysv" ]; then
> > +       # systemd is not PID 1
> > +       return
> > +    fi
> > +
> > +    # This function has been copied and adapted from lxc-fedora
> > +    rm -f ${rootfs}/etc/systemd/system/default.target
> > +    touch ${rootfs}/etc/fstab
> > +    chroot ${rootfs} ln -s /dev/null /etc/systemd/system/udev.service
> > +    chroot ${rootfs} ln -s /lib/systemd/system/multi-user.target /etc/systemd/system/default.target
> > +    # Make systemd honor SIGPWR
> > +    chroot ${rootfs} ln -s /lib/systemd/system/halt.target /etc/systemd/system/sigpwr.target
> > +    sed -e 's/^ConditionPathExists=/# ConditionPathExists=/' \
> > +        -e 's/After=dev-%i.device/After=/' \
> > +        < ${rootfs}/lib/systemd/system/getty\@.service \
> > +        > ${rootfs}/etc/systemd/system/getty\@.service
> > +    # Setup getty service on the 4 ttys we are going to allow in the
> > +    # default config.  Number should match lxc.tty
> > +    ( cd ${rootfs}/etc/systemd/system/getty.target.wants
> > +        for i in 1 2 3 4 ; do ln -sf ../getty\@.service getty at tty${i}.service; done )
> > +
> > +    return 0
> > +}
> > +
> >  cleanup()
> >  {
> >      rm -rf $cache/partial-$release-$arch
> > @@ -522,6 +550,8 @@ if [ $? -ne 0 ]; then
> >      exit 1
> >  fi
> >  
> > +configure_debian_systemd $rootfs
> > +
> >  copy_configuration $path $rootfs $name $arch
> >  if [ $? -ne 0 ]; then
> >      echo "failed write configuration file"
> > -- 
> > 2.1.3
> > 
> > _______________________________________________
> > lxc-devel mailing list
> > lxc-devel at lists.linuxcontainers.org
> > http://lists.linuxcontainers.org/listinfo/lxc-devel
> _______________________________________________
> lxc-devel mailing list
> lxc-devel at lists.linuxcontainers.org
> http://lists.linuxcontainers.org/listinfo/lxc-devel
> 

-- 
Michael H. Warfield (AI4NB) | (770) 978-7061 |  mhw at WittsEnd.com
   /\/\|=mhw=|\/\/          | (678) 463-0932 |  http://www.wittsend.com/mhw/
   NIC whois: MHW9          | An optimist believes we live in the best of all
 PGP Key: 0x674627FF        | possible worlds.  A pessimist is sure of it!

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 465 bytes
Desc: This is a digitally signed message part
URL: <http://lists.linuxcontainers.org/pipermail/lxc-devel/attachments/20141121/81917419/attachment.sig>


More information about the lxc-devel mailing list