You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

61 lines
1.6 KiB

1 year ago
#!/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
[ $(id -u) = 0 ] || exec sudo $0 $@
. $(dirname $(realpath $0))/functions
CONFIG="$1"
[ -r "$CONFIG" ] || die "Missing configuration $CONFIG"
config NAME $(basename $1 .${1##*.})
config LOG /tmp/oly-$NAME.log
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 ] || ip netns add $NAME
exec env UNSHARED=yes unshare -m $0 $@ > $LOG 2>&1 &
echo "Logging to $LOG" >&2
exit 0
fi
config BASE
config LIVE "$BASE/live"
config UPPER "$BASE/root"
config WORK "$BASE/work"
config LOWER "/"
config CABLES ""
config START "networking ssh"
config SUBSHELL /bin/sh
config STOP ""
# Setup virtual cabling and subhost's /etc/network/interfaces
setup_veth_cables $NAME $CABLES
# Set up the mount for this subhost, including a new tmpfs on its /run
echo setup_overlay "$NAME" "$LIVE" "$LOWER" "$UPPER" "$WORK"
setup_overlay "$NAME" "$LIVE" "$LOWER" "$UPPER" "$WORK"
exithandler() {
ip netns del $NAME
umount -R "$LIVE"
}
trap "exithandler" 0
CMD="unshare -fp --mount-proc ip netns exec $NAME chroot $LIVE /bin/sh"
echo "$CMD"
cat <<EOF | $CMD
set -x
mount --bind $UPPER/run /run
for srv in $START ; do service \$srv start ; done
exec /.reaper $NAME
EOF
echo "EXITED $CMD"
#echo "$STOP" | ip netns exec $NAME chroot $LIVE $SUBSHELL