From: Cameron Norman Date: Mon, 1 Dec 2014 21:29:26 +0000 (-0800) Subject: lxc-debian: adjust init system configurations X-Git-Tag: lxc-1.1.0.alpha3~4 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=2b75b644f8023fed4b215317ed806d822be3c106;p=thirdparty%2Flxc.git lxc-debian: adjust init system configurations Do as much as possible to allow containers switching from non-systemd to systemd to work as intended (but nothing that will cause side effects). Use update-rc.d disable instead of remove so the init scripts are not re-enabled when the package is updated Signed-off-by: Cameron Norman Acked-by: Stéphane Graber --- diff --git a/templates/lxc-debian.in b/templates/lxc-debian.in index 7e2f8f57d..ba225f905 100644 --- a/templates/lxc-debian.in +++ b/templates/lxc-debian.in @@ -108,10 +108,10 @@ EOF fi # remove pointless services in a container - chroot $rootfs /usr/sbin/update-rc.d -f checkroot.sh remove - chroot $rootfs /usr/sbin/update-rc.d -f umountfs remove - chroot $rootfs /usr/sbin/update-rc.d -f hwclock.sh remove - chroot $rootfs /usr/sbin/update-rc.d -f hwclockfirst.sh remove + chroot $rootfs /usr/sbin/update-rc.d -f checkroot.sh disable + chroot $rootfs /usr/sbin/update-rc.d -f umountfs disable + chroot $rootfs /usr/sbin/update-rc.d -f hwclock.sh disable + chroot $rootfs /usr/sbin/update-rc.d -f hwclockfirst.sh disable # generate new SSH keys if [ -x $rootfs/var/lib/dpkg/info/openssh-server.postinst ]; then @@ -187,26 +187,33 @@ configure_debian_systemd() { path=$1 rootfs=$2 + init="$(chroot ${rootfs} dpkg-query --search /sbin/init | cut -d : -f 1)" - if [ "$init" != "systemd-sysv" ]; then - # systemd is not PID 1 - return + if [ "$init" = "systemd-sysv" ]; then + # only appropiate when systemd is PID 1 + echo 'lxc.autodev = 1' >> "$path/config" + echo 'lxc.kmsg = 0' >> "$path/config" + fi + + # this only works if we have getty@.service to manipulate + if [ -f ${rootfs}/lib/systemd/system/getty\@.service ]; then + sed -e 's/^ConditionPathExists=/# ConditionPathExists=/' \ + -e 's/After=dev-%i.device/After=/' \ + < ${rootfs}/lib/systemd/system/getty\@.service \ + > ${rootfs}/etc/systemd/system/getty\@.service fi - echo 'lxc.autodev = 1' >> "$path/config" - echo 'lxc.kmsg = 0' >> "$path/config" + # just in case systemd is not installed + mkdir -p ${rootfs}/{lib,etc}/systemd/system + mkdir -p ${rootfs}/etc/systemd/system/getty.target.wants # 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 /dev/null /etc/systemd/system/systemd-udevd.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