#
# Script to stop the nominated overlay subhost
+OVERLAYDIR="$(dirname $(realpath $0))"
+
[ $(id -u) = 0 ] || exec sudo $0 $@
-. $(dirname $(realpath $0))/functions XXX
+. $OVERLAYDIR/functions $*
-NAME="$1"
+CONFIG="$1"
+[ -r "$CONFIG" ] || die "Missing configuration $CONFIG"
-[ -z "$NAME" ] && echo "Select subhost: $(list_running)" && exit 0
+config NAME $(basename $1 .${1##*.})
+config START "ssh networking"
+config LIVE
read USPID RSPID <<EOF
$(is_live $NAME)
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