Control: tag -1 patch

Hello,

On Tue, Oct 21, 2014 at 01:06:08PM -0200, Antonio Terceiro wrote:
> Package: lxc
> Version: 1:1.0.6-3
> Severity: normal
> 
> I have created a fresh jessie container, which got systemd as its init.
> When I start it in the foreground, then its console shows up
> just fine in my current terminal.
> 
> When I start the container the background (lxc-start -d), however:
> 
> - I cannot attach to it using lxc-console; there is never any output there.
> - I cannot stop it with lxc-stop without -k (i.e. forced kill)

Indeed, adapting the systemd setup from the lxc-fedora template does the
trick. The attached patch solves both issues.

I have just posted a proper git patch version of this patch to the
upstream mailing list.

Daniel, it would be really nice if we got this in Jessie.

-- 
Antonio Terceiro <[email protected]>
Author: Antonio Terceiro <[email protected]>
Description: lxc-debian: support systemd as PID 1
 Containers with systemd need a somewhat special setup, which I borrowed
 from lxc-fedora.

--- a/templates/lxc-debian.in
+++ b/templates/lxc-debian.in
@@ -159,6 +159,34 @@ EOF
     return 0
 }
 
+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@tty${i}.service; done )
+
+    return 0
+}
+
 cleanup()
 {
     rm -rf $cache/partial-$release-$arch
@@ -452,6 +480,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"

Attachment: signature.asc
Description: Digital signature

Reply via email to