3 # This boot method runs a service subhost with a root filesystem that
4 # is an overlay of the subhost's root and an OS root. The service
5 # subhost is defined by a configuration file named on teh command line
7 OVERLAYDIR="$(realpath $(dirname $0))"
9 [ $(id -u) = 0 ] || exec sudo $0 $@
10 . $(dirname $(realpath $0))/functions $*
13 [ -r "$CONFIG" ] || die "Missing configuration $CONFIG"
15 config NAME $(basename $1 .${1##*.})
16 config LOG /tmp/oly-$NAME.log
18 if [ -z "$UNSHARED" ] ; then
21 # Create the network namespace for the subhost, then trigger
22 # detached re-run with unshared mount namespace
23 [ -r /run/netns/$NAME ] || {
25 ip netns exec $NAME ip link set lo up
27 exec env UNSHARED=yes unshare -m $0 $@ > $LOG 2>&1 &
28 echo "Logging to $LOG" >&2
33 BASE="$(cd $(dirname $CONFIG); realpath $BASE)"
35 [ -z "$BASE" ] && die "BASE is unset; bogus $CONFIG ?"
36 [ -d "$BASE" ] || die "$BASE is not a directory; bogus $CONFIG ?"
37 cd "$BASE" || die "$BASE is inaccessible"
39 config LIVE "$BASE/live"
40 config UPPER "$BASE/root"
41 config WORK "$BASE/work"
44 config START "networking ssh"
45 config SUBSHELL /bin/sh
47 # Setup virtual cabling
48 setup_veth_cables $NAME $CABLES
50 # Set up the mount for this subhost, including a new tmpfs on its /run
51 # and a default $UPPER/etc/network/interfaces if needed
52 echo setup_overlay "$NAME" "$LIVE" "$LOWER" "$UPPER" "$WORK"
53 setup_overlay "$NAME" "$LIVE" "$LOWER" "$UPPER" "$WORK"
57 [ "$LOWER" != "$LIVE" ] && umount -R "$LIVE"
58 [ -f "${UPPER%% *}" ] && [ -x "${UPPER%% *}" ] && \
59 env ACTION=teardown $UPPER
63 CMD="unshare -fp --mount-proc ip netns exec $NAME chroot $LIVE /bin/sh"
70 mount -t proc proc /proc
71 mount -t devpts devpts /dev/pts
72 mount -t sysfs sysfs /sys
73 if [ "$RAM_SIZE" != "none" ] && ! grep -q '/run tmpfs' /proc/mounts ; then
74 mount -t tmpfs -osize=$RAM_SIZE,mode=755 tmpfs /run
76 for srv in $START ; do service \$srv start ; done
78 [ \$# -gt 3 ] && return 0
79 echo "Starting dummy service" >&2
81 [ -p /run/dummy_service ] || mkfifo /run/dummy_service
82 ( printf dummy_service > /proc/self/comm ; read X < /run/dummy_service ) &
85 dummy_service /proc/*/comm