X-Git-Url: https://git.rrq.au/?a=blobdiff_plain;f=overlay-stop;h=132da7600e7b37453e94a10a748367fb04896055;hb=3d79be7fb7f458f5f09e2c9ab651bb7f4e8345e2;hp=d1e89acf581b8459e5aaf7a7f06627aa3a53e440;hpb=1d2caf8010011eac8f6e5d79cac03abcb6018953;p=rrq%2Foverlay-boot.git diff --git a/overlay-stop b/overlay-stop index d1e89ac..132da76 100755 --- a/overlay-stop +++ b/overlay-stop @@ -2,18 +2,21 @@ # # Script to stop the nominated overlay subhost -[ $(id -u) = 0 ] || exec sudo $0 $@ -. $(dirname $(realpath $0))/functions XXX +OVERLAYDIR="$(dirname $(realpath $0))" +. $OVERLAYDIR/functions $* -NAME="$1" - -[ -z "$NAME" ] && echo "Select subhost: $(list_running)" && exit 0 +subhost_name "$1" +subhost_config read USPID RSPID <&2 && exit 1 +if [ -z "$USPID" ] ; then + [ -r /run/netns/$NAME ] && ip netns del $NAME + echo "$NAME is not running" >&2 + exit 1 +fi if [ -z "$RSPID" ] ; then cat <&2 @@ -23,5 +26,18 @@ EOF exit 1 fi -CHILDPIDS="$(nsenter -t $RSPID -p -m ps -hopid --ppid 1)" -nsenter -t $RSPID -p -m kill $CHILDPIDS +START="$(reverse "$START")" +nsenter -t $RSPID -p -m -i -u \ + ip netns exec $NAME chroot $(realpath $LIVE) \ + /bin/sh -c "for srv in $START ; do service \$srv stop ; done" + +for p in $RSPID $USPID ; do + for S in 15 1 2 9 ; do + ps -hocmd $p || break + kill -$S $p + done +done + +[ -r /run/netns/$NAME ] && ip netns del $NAME + +true