From 1b251901764789bd547f50b8ad701f3089170ce3 Mon Sep 17 00:00:00 2001 From: "Jan Alexander Steffens (heftig)" Date: Wed, 28 Jun 2023 23:40:38 +0200 Subject: chore(arch-nspawn): Simplify args construction for systemd-nspawn --- src/arch-nspawn.in | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) (limited to 'src/arch-nspawn.in') diff --git a/src/arch-nspawn.in b/src/arch-nspawn.in index 1453ba0..53b77df 100644 --- a/src/arch-nspawn.in +++ b/src/arch-nspawn.in @@ -16,7 +16,6 @@ umask 0022 working_dir='' files=() -mount_args=() usage() { echo "Usage: ${0##*/} [options] working-dir [systemd-nspawn arguments]" @@ -56,6 +55,15 @@ shift 1 [[ -z $working_dir ]] && die 'Please specify a working directory.' +nspawn_args=( + --quiet + --directory="$working_dir" + --setenv="PATH=/usr/local/sbin:/usr/local/bin:/usr/bin" + --register=no + --keep-unit + --as-pid2 +) + if (( ${#cache_dirs[@]} == 0 )); then mapfile -t cache_dirs < <(pacman-conf --config "${pac_conf:-$working_dir/etc/pacman.conf}" CacheDir) fi @@ -83,10 +91,10 @@ while read -r line; do done done < <(pacman-conf --config "${pac_conf:-$working_dir/etc/pacman.conf}" --repo-list) -mount_args+=("--bind=${cache_dirs[0]//:/\\:}") +nspawn_args+=(--bind="${cache_dirs[0]//:/\\:}") for cache_dir in "${cache_dirs[@]:1}"; do - mount_args+=("--bind-ro=${cache_dir//:/\\:}") + nspawn_args+=(--bind-ro="${cache_dir//:/\\:}") done # {{{ functions @@ -129,9 +137,4 @@ else set_arch="${CARCH}" fi -exec ${CARCH:+setarch "$set_arch"} systemd-nspawn -q \ - -D "$working_dir" \ - -E "PATH=/usr/local/sbin:/usr/local/bin:/usr/bin" \ - --register=no --keep-unit --as-pid2 \ - "${mount_args[@]}" \ - "$@" +exec ${CARCH:+setarch "$set_arch"} systemd-nspawn "${nspawn_args[@]}" "$@" -- cgit v1.2.3-54-g00ecf From 5f4fd52e3836ddddb25a0f9e15d0acfed06f693d Mon Sep 17 00:00:00 2001 From: "Jan Alexander Steffens (heftig)" Date: Thu, 29 Jun 2023 01:12:41 +0200 Subject: feat(arch-nspawn): Use a unique scope name instead of --keep-unit `--keep-unit` is really only for use in services like `systemd-nspawn@.service`. The parameter was added in commit 000ea6c7bbf6191b because systemd-nspawn defaults the name of the machine (and thus the generated scope) to the name of the working directory, which is not unique. Thus spawning a container from `archbuild/extra-x86_64/foo` while `archbuild/testing-x86_64/foo` is already running would fail. We can avoid the unit conflict by giving the container a unique machine name. Creating a scope also allows us to place the container in a slice hierarchy for resource control. --- src/arch-nspawn.in | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'src/arch-nspawn.in') diff --git a/src/arch-nspawn.in b/src/arch-nspawn.in index 53b77df..1eba0a6 100644 --- a/src/arch-nspawn.in +++ b/src/arch-nspawn.in @@ -60,7 +60,8 @@ nspawn_args=( --directory="$working_dir" --setenv="PATH=/usr/local/sbin:/usr/local/bin:/usr/bin" --register=no - --keep-unit + --slice="devtools-$(systemd-escape "${SUDO_USER:-$USER}")" + --machine="arch-nspawn-$$" --as-pid2 ) -- cgit v1.2.3-54-g00ecf