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.

50 lines
1.3 KiB

9 months ago
#!/bin/sh
#
# This boot scripts runs a service subhost as defined by the
# configuration file named on the command line.
# See "man overlay-boot" for details.
9 months ago
set -x
PROGRAMDIR="$(dirname $(realpath $0))"
. $PROGRAMDIR/functions
subhost_name $1
9 months ago
if [ -z "$UNSHARED" ] ; then
if [ ! -r /run/netns/$NAME ] ; then
ip netns add $NAME
ip netns exec $NAME ip link set lo up || exit 1
fi
9 months ago
exec env UNSHARED=yes unshare -m $0 $@ > $LOG 2>&1 &
echo "Logging to $LOG" >&2
exit 0
fi
subhost_config
9 months ago
setup_veth_cables $NAME $CABLES
setup_overlay "$NAME" "$LIVE" "$LOWER" "$UPPER" "$WORK"
setup_cgroup2_accounting "$NAME" "$$"
9 months ago
exithandler() {
ip netns del $NAME
[ "$UPPER" != "$LIVE" ] && umount -R "$LIVE"
9 months ago
}
trap "exithandler" 0
# This process has an unshared mount namespace, so we unmount almost
# everything before chroot. Exceptions are: $LIVE and anything mounted
# below that, "/run/netns/$NAME" and its parent paths (incidentally
# including "/" as well) and "/proc".
sort -rk2,2 < /proc/mounts | while read D P A2 ; do
beginswith "$P" "$LIVE" && continue
beginswith "/run/netns/$NAME" "$P" && continue
[ "$P" = /proc ] && continue
umount "$P"
done
echo "Starting $NAME"
env CONFIG="$CONFIG" $INIT | \
unshare -fp --mount-proc -i -u \
ip netns exec $NAME chroot $LIVE /bin/sh
echo "Exited $NAME"