Commit 2b75b644 by Cameron Norman Committed by Stéphane Graber

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: 's avatarCameron Norman <camerontnorman@gmail.com> Acked-by: 's avatarStéphane Graber <stgraber@ubuntu.com>
parent be54cb1c
...@@ -108,10 +108,10 @@ EOF ...@@ -108,10 +108,10 @@ EOF
fi fi
# remove pointless services in a container # 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 checkroot.sh disable
chroot $rootfs /usr/sbin/update-rc.d -f umountfs remove chroot $rootfs /usr/sbin/update-rc.d -f umountfs disable
chroot $rootfs /usr/sbin/update-rc.d -f hwclock.sh remove chroot $rootfs /usr/sbin/update-rc.d -f hwclock.sh disable
chroot $rootfs /usr/sbin/update-rc.d -f hwclockfirst.sh remove chroot $rootfs /usr/sbin/update-rc.d -f hwclockfirst.sh disable
# generate new SSH keys # generate new SSH keys
if [ -x $rootfs/var/lib/dpkg/info/openssh-server.postinst ]; then if [ -x $rootfs/var/lib/dpkg/info/openssh-server.postinst ]; then
...@@ -187,26 +187,33 @@ configure_debian_systemd() ...@@ -187,26 +187,33 @@ configure_debian_systemd()
{ {
path=$1 path=$1
rootfs=$2 rootfs=$2
init="$(chroot ${rootfs} dpkg-query --search /sbin/init | cut -d : -f 1)" init="$(chroot ${rootfs} dpkg-query --search /sbin/init | cut -d : -f 1)"
if [ "$init" != "systemd-sysv" ]; then if [ "$init" = "systemd-sysv" ]; then
# systemd is not PID 1 # only appropiate when systemd is PID 1
return 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 fi
echo 'lxc.autodev = 1' >> "$path/config" # just in case systemd is not installed
echo 'lxc.kmsg = 0' >> "$path/config" 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 # This function has been copied and adapted from lxc-fedora
rm -f ${rootfs}/etc/systemd/system/default.target rm -f ${rootfs}/etc/systemd/system/default.target
touch ${rootfs}/etc/fstab 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 chroot ${rootfs} ln -s /lib/systemd/system/multi-user.target /etc/systemd/system/default.target
# Make systemd honor SIGPWR # Make systemd honor SIGPWR
chroot ${rootfs} ln -s /lib/systemd/system/halt.target /etc/systemd/system/sigpwr.target 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 # Setup getty service on the 4 ttys we are going to allow in the
# default config. Number should match lxc.tty # default config. Number should match lxc.tty
( cd ${rootfs}/etc/systemd/system/getty.target.wants ( cd ${rootfs}/etc/systemd/system/getty.target.wants
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment