From 6e1a024c4ca428975088057298f4552e2b16b928 Mon Sep 17 00:00:00 2001 From: Valentin David Date: Wed, 9 Nov 2022 16:32:36 +0100 Subject: [PATCH] Generate symlinks from install section in units Also ensure units are enable with a preset. And move all system unit symlinks from `/etc` to `/lib` instead of few of them. --- hooks/095-preset-all.chroot | 6 ++++ hooks/100-systemd-in-lib.chroot | 31 +++++++++++++++++-- .../system-preset/90-ubuntu-core.preset | 8 +++++ .../snapd.seeded.service | 1 - .../system/keep-entangled-mounts.target | 3 ++ .../var-lib-snapd-save.mount | 1 - .../core.start-snapd.service | 1 - .../snapd.seeded.service | 1 - .../snapd.sshd-keygen.service | 1 - .../multi-user.target.wants/swapfile.service | 1 - .../lib/systemd/system/remount-data.service | 3 ++ .../lib/systemd/system/remount-seed.service | 3 ++ .../keep-entangled-mounts.target | 1 - .../remount-data.service | 1 - .../remount-seed.service | 1 - .../systemd/system/snapd.sshd-keygen.service | 3 ++ .../systemd/system/var-lib-snapd-save.mount | 3 ++ 17 files changed, 57 insertions(+), 12 deletions(-) create mode 100755 hooks/095-preset-all.chroot create mode 100644 static/usr/lib/systemd/system-preset/90-ubuntu-core.preset delete mode 120000 static/usr/lib/systemd/system/cloud-final.service.wants/snapd.seeded.service delete mode 120000 static/usr/lib/systemd/system/local-fs.target.requires/var-lib-snapd-save.mount delete mode 120000 static/usr/lib/systemd/system/multi-user.target.wants/core.start-snapd.service delete mode 120000 static/usr/lib/systemd/system/multi-user.target.wants/snapd.seeded.service delete mode 120000 static/usr/lib/systemd/system/multi-user.target.wants/snapd.sshd-keygen.service delete mode 120000 static/usr/lib/systemd/system/multi-user.target.wants/swapfile.service delete mode 120000 static/usr/lib/systemd/system/shutdown.target.wants/keep-entangled-mounts.target delete mode 120000 static/usr/lib/systemd/system/shutdown.target.wants/remount-data.service delete mode 120000 static/usr/lib/systemd/system/shutdown.target.wants/remount-seed.service diff --git a/hooks/095-preset-all.chroot b/hooks/095-preset-all.chroot new file mode 100755 index 00000000..6b24aa25 --- /dev/null +++ b/hooks/095-preset-all.chroot @@ -0,0 +1,6 @@ +#!/bin/sh + +set -eux + +systemctl preset-all +systemctl --global preset-all diff --git a/hooks/100-systemd-in-lib.chroot b/hooks/100-systemd-in-lib.chroot index 9289b658..2ca48d1a 100755 --- a/hooks/100-systemd-in-lib.chroot +++ b/hooks/100-systemd-in-lib.chroot @@ -3,7 +3,32 @@ set -eux echo "ensure the systemd target.wants are in /lib instead of /etc" -for d in multi-user.target.wants sysinit.target.wants timers.target.wants; do - mv etc/systemd/system/"$d"/* lib/systemd/system/"$d" -done +for path in /etc/systemd/system/*.wants /etc/systemd/system/*.requires; do + if ! [ -d "${path}" ]; then + continue + fi + want="$(basename "${path}")" + for link in "${path}"/*; do + if ! [ -L "${link}" ]; then + continue + fi + mkdir -p /lib/systemd/system/"${want}" + source="$(basename "${link}")" + unitpath="$(realpath "${link}")" + case "${unitpath}" in + /lib/systemd/system/*) + ln -rs "${unitpath}" "/lib/systemd/system/${want}/${source}" + ;; + /usr/lib/systemd/system/*) + ln -rs "${unitpath}" "/usr/lib/systemd/system/${want}/${source}" + ;; + *) + ln -s "${unitpath}" "/lib/systemd/system/${want}/${source}" + ;; + esac + rm "${link}" + done + + rmdir "${path}" +done diff --git a/static/usr/lib/systemd/system-preset/90-ubuntu-core.preset b/static/usr/lib/systemd/system-preset/90-ubuntu-core.preset new file mode 100644 index 00000000..93dac04b --- /dev/null +++ b/static/usr/lib/systemd/system-preset/90-ubuntu-core.preset @@ -0,0 +1,8 @@ +enable core.start-snapd.service +enable keep-entangled-mounts.target +enable plymouth-show-install.service +enable remount-data.service +enable remount-seed.service +enable snapd.seeded.service +enable snapd.sshd-keygen.service +enable swapfile.service diff --git a/static/usr/lib/systemd/system/cloud-final.service.wants/snapd.seeded.service b/static/usr/lib/systemd/system/cloud-final.service.wants/snapd.seeded.service deleted file mode 120000 index 92ab262a..00000000 --- a/static/usr/lib/systemd/system/cloud-final.service.wants/snapd.seeded.service +++ /dev/null @@ -1 +0,0 @@ -../snapd.seeded.service \ No newline at end of file diff --git a/static/usr/lib/systemd/system/keep-entangled-mounts.target b/static/usr/lib/systemd/system/keep-entangled-mounts.target index 8e568eae..ab51885f 100644 --- a/static/usr/lib/systemd/system/keep-entangled-mounts.target +++ b/static/usr/lib/systemd/system/keep-entangled-mounts.target @@ -5,3 +5,6 @@ Wants=run-mnt-data.mount Wants=run-mnt-ubuntu\x2dseed.mount Wants=usr-lib-modules.mount Wants=run-mnt-kernel.mount + +[Install] +WantedBy=shutdown.target diff --git a/static/usr/lib/systemd/system/local-fs.target.requires/var-lib-snapd-save.mount b/static/usr/lib/systemd/system/local-fs.target.requires/var-lib-snapd-save.mount deleted file mode 120000 index f9949035..00000000 --- a/static/usr/lib/systemd/system/local-fs.target.requires/var-lib-snapd-save.mount +++ /dev/null @@ -1 +0,0 @@ -../var-lib-snapd-save.mount \ No newline at end of file diff --git a/static/usr/lib/systemd/system/multi-user.target.wants/core.start-snapd.service b/static/usr/lib/systemd/system/multi-user.target.wants/core.start-snapd.service deleted file mode 120000 index d4c3e70f..00000000 --- a/static/usr/lib/systemd/system/multi-user.target.wants/core.start-snapd.service +++ /dev/null @@ -1 +0,0 @@ -../core.start-snapd.service \ No newline at end of file diff --git a/static/usr/lib/systemd/system/multi-user.target.wants/snapd.seeded.service b/static/usr/lib/systemd/system/multi-user.target.wants/snapd.seeded.service deleted file mode 120000 index 92ab262a..00000000 --- a/static/usr/lib/systemd/system/multi-user.target.wants/snapd.seeded.service +++ /dev/null @@ -1 +0,0 @@ -../snapd.seeded.service \ No newline at end of file diff --git a/static/usr/lib/systemd/system/multi-user.target.wants/snapd.sshd-keygen.service b/static/usr/lib/systemd/system/multi-user.target.wants/snapd.sshd-keygen.service deleted file mode 120000 index 09b64df8..00000000 --- a/static/usr/lib/systemd/system/multi-user.target.wants/snapd.sshd-keygen.service +++ /dev/null @@ -1 +0,0 @@ -../snapd.sshd-keygen.service \ No newline at end of file diff --git a/static/usr/lib/systemd/system/multi-user.target.wants/swapfile.service b/static/usr/lib/systemd/system/multi-user.target.wants/swapfile.service deleted file mode 120000 index 0003d393..00000000 --- a/static/usr/lib/systemd/system/multi-user.target.wants/swapfile.service +++ /dev/null @@ -1 +0,0 @@ -../swapfile.service \ No newline at end of file diff --git a/static/usr/lib/systemd/system/remount-data.service b/static/usr/lib/systemd/system/remount-data.service index 7fc82279..e1ee41cd 100644 --- a/static/usr/lib/systemd/system/remount-data.service +++ b/static/usr/lib/systemd/system/remount-data.service @@ -8,3 +8,6 @@ Before=shutdown.target [Service] Type=oneshot ExecStart=/bin/mount -o remount,ro /run/mnt/data + +[Install] +WantedBy=shutdown.target diff --git a/static/usr/lib/systemd/system/remount-seed.service b/static/usr/lib/systemd/system/remount-seed.service index 3aae98b8..1d7b1892 100644 --- a/static/usr/lib/systemd/system/remount-seed.service +++ b/static/usr/lib/systemd/system/remount-seed.service @@ -8,3 +8,6 @@ Before=shutdown.target [Service] Type=oneshot ExecStart=/bin/mount -o remount,ro /run/mnt/ubuntu-seed + +[Install] +WantedBy=shutdown.target diff --git a/static/usr/lib/systemd/system/shutdown.target.wants/keep-entangled-mounts.target b/static/usr/lib/systemd/system/shutdown.target.wants/keep-entangled-mounts.target deleted file mode 120000 index 3b629ae2..00000000 --- a/static/usr/lib/systemd/system/shutdown.target.wants/keep-entangled-mounts.target +++ /dev/null @@ -1 +0,0 @@ -../keep-entangled-mounts.target \ No newline at end of file diff --git a/static/usr/lib/systemd/system/shutdown.target.wants/remount-data.service b/static/usr/lib/systemd/system/shutdown.target.wants/remount-data.service deleted file mode 120000 index b918c39f..00000000 --- a/static/usr/lib/systemd/system/shutdown.target.wants/remount-data.service +++ /dev/null @@ -1 +0,0 @@ -../remount-data.service \ No newline at end of file diff --git a/static/usr/lib/systemd/system/shutdown.target.wants/remount-seed.service b/static/usr/lib/systemd/system/shutdown.target.wants/remount-seed.service deleted file mode 120000 index 886bb720..00000000 --- a/static/usr/lib/systemd/system/shutdown.target.wants/remount-seed.service +++ /dev/null @@ -1 +0,0 @@ -../remount-seed.service \ No newline at end of file diff --git a/static/usr/lib/systemd/system/snapd.sshd-keygen.service b/static/usr/lib/systemd/system/snapd.sshd-keygen.service index f5148a1d..7ec189a1 100644 --- a/static/usr/lib/systemd/system/snapd.sshd-keygen.service +++ b/static/usr/lib/systemd/system/snapd.sshd-keygen.service @@ -6,3 +6,6 @@ Before=sshd.service Type=oneshot RemainAfterExit=yes ExecStart=/usr/bin/core-sshd-host-keygen + +[Install] +WantedBy=multi-user.target diff --git a/static/usr/lib/systemd/system/var-lib-snapd-save.mount b/static/usr/lib/systemd/system/var-lib-snapd-save.mount index 3796ed4f..e01c5003 100644 --- a/static/usr/lib/systemd/system/var-lib-snapd-save.mount +++ b/static/usr/lib/systemd/system/var-lib-snapd-save.mount @@ -6,3 +6,6 @@ What=/run/mnt/ubuntu-save Where=/var/lib/snapd/save Options=bind Type=none + +[Install] +WantedBy=local-fs.target