X-Git-Url: https://git.rrq.au/?a=blobdiff_plain;f=overlay-boot;h=d635da4347739db34020cd6856382d5c6f7827f9;hb=7f766756c6d328a4a8d57a274a215f67376af68d;hp=e94620ec70746b22f14fc61373811b9ef39e8090;hpb=e167fa970f34adaeeac05db7e57c7d6b5307bb2d;p=rrq%2Foverlay-boot.git diff --git a/overlay-boot b/overlay-boot index e94620e..d635da4 100755 --- a/overlay-boot +++ b/overlay-boot @@ -1,88 +1,35 @@ #!/bin/sh # -# This boot method runs a service subhost with a root filesystem that -# 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 +# This boot scripts runs a service subhost as defined by the +# configuration file named on the command line. +# See "man overlay-boot" for details. -OVERLAYDIR="$(dirname $(realpath $0))" +PROGRAMDIR="$(dirname $(realpath $0))" +. $PROGRAMDIR/functions -[ $(id -u) = 0 ] || exec sudo $0 $@ -. $OVERLAYDIR/functions $* - -CONFIG="$1" -[ -r "$CONFIG" ] || die "Missing configuration $CONFIG" - -config NAME $(basename $1 .${1##*.}) -config LOG /tmp/oly-$NAME.log +subhost_name $1 if [ -z "$UNSHARED" ] ; then - # Pre-unsharing: - # - # Create the network namespace for the subhost, then trigger - # detached re-run with unshared mount namespace - [ -r /run/netns/$NAME ] || { + if [ ! -r /run/netns/$NAME ] ; then ip netns add $NAME - ip netns exec $NAME ip link set lo up - } + ip netns exec $NAME ip link set lo up || exit 1 + fi 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" -config LOWER "/" -config CABLES "" -config START "networking ssh" -config SUBSHELL /bin/sh - -# Setup virtual cabling +subhost_config 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 - [ "$LOWER" != "$LIVE" ] && umount -R "$LIVE" - [ -f "${UPPER%% *}" ] && [ -x "${UPPER%% *}" ] && \ - env ACTION=teardown $UPPER + [ "$UPPER" != "$LIVE" ] && umount -R "$LIVE" } trap "exithandler" 0 CMD="unshare -fp --mount-proc -i -u 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 +env CONFIG="$CONFIG" $INIT | $CMD echo "EXITED $CMD"