X-Git-Url: https://git.rrq.au/?a=blobdiff_plain;f=overlay-stop;h=132da7600e7b37453e94a10a748367fb04896055;hb=HEAD;hp=82961ec118b88eb53a6a98a7aeee1b53cc1791bd;hpb=018cee4d13bc670479131ae2167dad4824ab1c47;p=rrq%2Foverlay-boot.git diff --git a/overlay-stop b/overlay-stop index 82961ec..132da76 100755 --- a/overlay-stop +++ b/overlay-stop @@ -3,22 +3,20 @@ # Script to stop the nominated overlay subhost OVERLAYDIR="$(dirname $(realpath $0))" - -[ $(id -u) = 0 ] || exec sudo $0 $@ . $OVERLAYDIR/functions $* -CONFIG="$1" -[ -r "$CONFIG" ] || die "Missing configuration $CONFIG" - -config NAME $(basename $1 .${1##*.}) -config START "ssh networking" -config LIVE +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 @@ -28,16 +26,18 @@ EOF exit 1 fi -# function to reverse the $* words -reverse() { - local OUT="" - for w in $* ; do ; OUT="$w $OUT" ; done - echo "${OUT% }" -} - START="$(reverse "$START")" -if nsenter -t $RSPID -p -m -i -u ip netns exec $NAME chroot $LIVE /bin/sh \ - -c "for srv in $START ; do service \$srv stop ; done" ; then - CHILDPIDS="$(nsenter -t $RSPID -p -m ps -hopid --ppid 1)" - nsenter -t $RSPID -p -m kill $CHILDPIDS -fi +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