#!/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. set -x PROGRAMDIR="$(dirname $(realpath $0))" . $PROGRAMDIR/functions subhost_name $1 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 exec env UNSHARED=yes unshare -m $0 $@ > $LOG 2>&1 & echo "Logging to $LOG" >&2 exit 0 fi subhost_config setup_veth_cables $NAME $CABLES setup_overlay "$NAME" "$LIVE" "$LOWER" "$UPPER" "$WORK" setup_cgroup2_accounting "$NAME" "$$" exithandler() { ip netns del $NAME [ "$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" env CONFIG="$CONFIG" $INIT | $CMD echo "EXITED $CMD"