X-Git-Url: https://git.rrq.au/?a=blobdiff_plain;f=overlay-stop;h=82961ec118b88eb53a6a98a7aeee1b53cc1791bd;hb=018cee4d13bc670479131ae2167dad4824ab1c47;hp=2c57c52f529610d65d8c8ddaffa5dccce6524d57;hpb=94d01e2775fdeb67ab729b4e7b98867e6cd97c16;p=rrq%2Foverlay-boot.git diff --git a/overlay-stop b/overlay-stop index 2c57c52..82961ec 100755 --- a/overlay-stop +++ b/overlay-stop @@ -2,16 +2,23 @@ # # Script to stop the nominated overlay subhost +OVERLAYDIR="$(dirname $(realpath $0))" + [ $(id -u) = 0 ] || exec sudo $0 $@ -. $(dirname $(realpath $0))/functions XXX +. $OVERLAYDIR/functions $* + +CONFIG="$1" +[ -r "$CONFIG" ] || die "Missing configuration $CONFIG" -NAME="$1" +config NAME $(basename $1 .${1##*.}) +config START "ssh networking" +config LIVE read USPID RSPID <&2 && exit 1 +[ -z "$USPID" ] && echo "$NAME is snot running" >&2 && exit 1 if [ -z "$RSPID" ] ; then cat <&2 @@ -21,5 +28,16 @@ EOF exit 1 fi -CHILDPIDS="$(nsenter -t $RSPID -p -m ps -hopid --ppid 1)" -nsenter -t $RSPID -p -m kill $CHILDPIDS +# 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