Add bind-mount for /etc/adjtime to make subhost use host clock without ado
[rrq/overlay-boot.git] / overlay-stop
index 82961ec118b88eb53a6a98a7aeee1b53cc1791bd..132da7600e7b37453e94a10a748367fb04896055 100755 (executable)
@@ -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 <<EOF
 $(is_live $NAME)
 EOF
 
-[ -z "$USPID" ] && echo "$NAME is snot running" >&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 <<EOF >&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