X-Git-Url: https://git.rrq.au/?a=blobdiff_plain;f=overlay-boot;h=75939fe97a2b670863cabf5252297f59e1bd10c7;hb=c41e4d944252a03eb80c9f3a1b8939562c4f5453;hp=239ae1cc7228d4c4a1b06a86b5b44a0e4e336516;hpb=df3ccb2170beff852f8ec7d421709c5e85bafc7d;p=rrq%2Foverlay-boot.git diff --git a/overlay-boot b/overlay-boot index 239ae1c..75939fe 100755 --- a/overlay-boot +++ b/overlay-boot @@ -4,9 +4,10 @@ # is an overlay of the subhost's root and an OS root. The service # subhost is defined by a configuration file named on teh command line -[ $(id -u) = 0 ] || exec sudo $0 $@ +OVERLAYDIR="$(realpath $(dirname $0))" -. $(dirname $(realpath $0))/functions +[ $(id -u) = 0 ] || exec sudo $0 $@ +. $(dirname $(realpath $0))/functions $* CONFIG="$1" [ -r "$CONFIG" ] || die "Missing configuration $CONFIG" @@ -19,13 +20,22 @@ if [ -z "$UNSHARED" ] ; then # # Create the network namespace for the subhost, then trigger # detached re-run with unshared mount namespace - [ -r /run/netns/$NAME ] || ip netns add $NAME + [ -r /run/netns/$NAME ] || { + ip netns add $NAME + ip netns exec $NAME ip link set lo up + } exec env UNSHARED=yes unshare -m $0 $@ > $LOG 2>&1 & echo "Logging to $LOG" >&2 exit 0 fi config BASE +BASE="$(cd $(dirname $CONFIG); realpath $BASE)" + +[ -z "$BASE" ] && die "BASE is unset; bogus $CONFIG ?" +[ -d "$BASE" ] || die "$BASE is not a directory; bogus $CONFIG ?" +cd "$BASE" || die "$BASE is inaccessible" + config LIVE "$BASE/live" config UPPER "$BASE/root" config WORK "$BASE/work" @@ -33,28 +43,46 @@ config LOWER "/" config CABLES "" config START "networking ssh" config SUBSHELL /bin/sh -config STOP "" -# Setup virtual cabling and subhost's /etc/network/interfaces +# Setup virtual cabling setup_veth_cables $NAME $CABLES # Set up the mount for this subhost, including a new tmpfs on its /run +# and a default $UPPER/etc/network/interfaces if needed echo setup_overlay "$NAME" "$LIVE" "$LOWER" "$UPPER" "$WORK" setup_overlay "$NAME" "$LIVE" "$LOWER" "$UPPER" "$WORK" exithandler() { ip netns del $NAME - umount -R "$LIVE" + [ "$LOWER" != "$LIVE" ] && umount -R "$LIVE" + [ -f "${UPPER%% *}" ] && [ -x "${UPPER%% *}" ] && \ + env ACTION=teardown $UPPER } trap "exithandler" 0 CMD="unshare -fp --mount-proc ip netns exec $NAME chroot $LIVE /bin/sh" echo "$CMD" + +config RAM_SIZE 50M + cat <&2 + set +x + [ -p /run/dummy_service ] || mkfifo /run/dummy_service + ( printf dummy_service > /proc/self/comm ; read X < /run/dummy_service ) & + set -x +} +dummy_service /proc/*/comm exec /.reaper $NAME EOF echo "EXITED $CMD" -#echo "$STOP" | ip netns exec $NAME chroot $LIVE $SUBSHELL