added documentation about failure reasons
[util-vserver.git] / util-vserver / scripts / vserver.stop
index 55af27d..b117826 100644 (file)
 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 
 if ! isVserverRunning "$VSERVER_DIR" S_CONTEXT; then
-    echo $"vserver '$VSERVER_NAME' is not running; aborting..."
-    umountVserver "$VSERVER_DIR"     &>/dev/null || :
-    disableInterfaces "$VSERVER_DIR" &>/dev/null || :
+    echo $"vserver '$VSERVER_NAME' is not running; aborting..." >&2
+    test "$OPTION_DEBUG" || exec 2>/dev/null >/dev/null
+    umountVserver     "$VSERVER_DIR" || :
+    disableInterfaces "$VSERVER_DIR" || :
     exit 1
 fi
 
+set -e
 generateOptions   "$VSERVER_DIR"
+set +e
 
-set -e
 cd "$VSERVER_DIR"/vdir/
 execScriptlets    "$VSERVER_DIR" "$VSERVER_NAME" pre-stop
 
 cd "$VSERVER_DIR"/vdir/
-"${NICE_CMD[@]}" \
+
+if test "$_IS_FAKEINIT" && \
+   $_VSERVER_INFO - FEATURE vkill && \
+   initpid=$($_VSERVER_INFO "$S_CONTEXT" INITPID 2>/dev/null); then
+    $_VKILL -s INT -- "$initpid" && "${INITCMD_STOP_SYNC[@]}" || :
+elif $_VSERVER_INFO - FEATURE migrate; then
+    "${NICE_CMD[@]}" \
+    ${USE_VNAMESPACE:+$_VNAMESPACE --enter "$S_CONTEXT" -- } \
+    $_VCONTEXT $SILENT_OPT --migrate --chroot --xid "$S_CONTEXT" -- \
+    "${INITCMD_STOP[@]}" && "${INITCMD_STOP_SYNC[@]}" || :
+else
+    "${NICE_CMD[@]}" \
     "$_CHBIND"       "${CHBIND_OPTS[@]}" \
     "$_EXEC_ULIMIT"  "$VSERVER_DIR/ulimits" \
-    "$_CHCONTEXT"    "${CHCONTEXT_OPTS[@]}" \
-    "$_CAPCHROOT"    "${CAPCHROOT_OPTS[@]}" . "${INITCMD_STOP[@]}"
+    ${USE_VNAMESPACE:+$_VNAMESPACE --enter "$S_CONTEXT"} \
+    $_CHCONTEXT_COMPAT    "${CHCONTEXT_OPTS[@]}" \
+    "$_CAPCHROOT"    "${CAPCHROOT_OPTS[@]}" "." \
+    "${INITCMD_STOP[@]}" && "${INITCMD_STOP_SYNC[@]}" || :
+fi
 
-"${INITCMD_STOP_SYNC[@]}"
 sendKillSequence  "$S_CONTEXT" "${INITKILL_SEQ[@]}"
 
+## Small hack... isVserverRunning removes stale runfiles as a sideeffect
+! isVserverRunning  "$VSERVER_DIR" || \
+    echo $"Vserver '$VSERVER_DIR' still running unexpectedly; please investigate it manually..." >&2
+
 execScriptlets    "$VSERVER_DIR" "$VSERVER_NAME" post-stop
     
 umountVserver     "$VSERVER_DIR" || :