nested lxd wip1

This commit is contained in:
pvincent
2024-02-26 22:57:41 +04:00
parent c874f2c180
commit 2bf8289238
5 changed files with 66 additions and 22 deletions
+18 -5
View File
@@ -97,7 +97,7 @@ runcmd:
final_message: "Container from datasource \$datasource is finally up, after \$UPTIME seconds"
EOF
)"
lxc init images:debian/$CONTAINER_RELEASE/cloud "$CONTAINER" --config user.user-data="$user_data" -q
lxc init local:debian/$CONTAINER_RELEASE/cloud "$CONTAINER" --config user.user-data="$user_data" -q
# allow directory `SHARED` to be read-write mounted
lxc config set "$CONTAINER" raw.idmap "both $(id -u) 0" -q
@@ -105,8 +105,11 @@ EOF
lxc config device add "$CONTAINER" SHARED disk source="$HOME/LXD/SHARED/$CONTAINER" path=/mnt/SHARED -q
lxc config device add "$CONTAINER" TOOLBOX disk source=/TOOLBOX path=/TOOLBOX -q
lxc config device add "$CONTAINER" DEBIAN_BASH disk source=$(realpath /opt/miaou-bash) path=/opt/miaou-bash -q
lxc config device add "$CONTAINER" MIAOU_BASH disk source=$(realpath /opt/miaou-bash) path=/opt/miaou-bash -q
# environment variables
lxc config set "$CONTAINER" environment.PATH /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/opt/miaou-bash/tools:/TOOLBOX -q
lxc config set "$CONTAINER" environment.container lxc -q
if [[ "$OPTION_NESTING" == true ]]; then
lxc config set "$CONTAINER" security.nesting true -q
@@ -123,8 +126,10 @@ EOF
lxc file push "$MIAOU_BASEDIR/templates/bottom/bottom.toml" "$CONTAINER/root/.config/bottom/bottom.toml" -q
# purge cloud-init after success
lxc exec "$CONTAINER" -- systemd-run -q -p After=cloud-final.service -p Type=oneshot --no-block bash -c '\
sleep 0.2 &&\
attempt=0
max_attempt=10
delay=0.2
while ! lxc exec "$CONTAINER" -- bash -c 'systemd-run -q -p After=cloud-final.service -p Type=oneshot --no-block bash -c "\
cloud-init status --wait &&\
cp /var/lib/cloud/data/status.json /root/cloud-status.json &&\
systemctl stop cloud-{config,final,init-local,init}.service &&\
@@ -133,7 +138,15 @@ EOF
apt-get purge -y cloud-init &&\
rm -rf /var/lib/cloud && \
userdel -rf debian \
'
" 2>/dev/null '; do
attempt=$((attempt++))
if [[ $attempt -gt $max_attempt ]]; then
echoerr "systemd unavailable after $(bc <<<"$max_attempt * $delay") seconds"
exit 1
else
sleep $delay
fi
done
if [[ "$OPTION_SAMEUSER" == true ]]; then
if ! lxc exec "$CONTAINER" -- grep "$miaou_user" /etc/passwd; then
+5
View File
@@ -413,6 +413,11 @@ function build_services() {
app=${item[5]}
name=${item[6]:-}
domain=${item[0]}
subdomain=${item[1]}
data=$(yqm ".services.\"$domain\".\"$subdomain\".data")
echo "domain=$domain, subdomain=$subdomain, data=$data"
recipe="$MIAOU_BASEDIR/recipes/$app/crud.sh"
if [[ -f "$recipe" ]]; then
echo "read [$app:$name] onto container <$container>"