added documentation about failure reasons
[util-vserver.git] / util-vserver / scripts / vserver.stop
index c6e6930..b117826 100644 (file)
@@ -17,8 +17,9 @@
 
 if ! isVserverRunning "$VSERVER_DIR" S_CONTEXT; then
     echo $"vserver '$VSERVER_NAME' is not running; aborting..." >&2
-    umountVserver     "$VSERVER_DIR" &>/dev/null || :
-    disableInterfaces "$VSERVER_DIR" &>/dev/null || :
+    test "$OPTION_DEBUG" || exec 2>/dev/null >/dev/null
+    umountVserver     "$VSERVER_DIR" || :
+    disableInterfaces "$VSERVER_DIR" || :
     exit 1
 fi
 
@@ -31,22 +32,31 @@ execScriptlets    "$VSERVER_DIR" "$VSERVER_NAME" pre-stop
 
 cd "$VSERVER_DIR"/vdir/
 
-if $_VSERVER_INFO - FEATURE migrate; then
-    ${USE_VNAMESPACE:+$_VNAMESPACE --enter "$S_CONTEXT"} \
-    $_VCONTEXT $SILENT_OPT --migrate --chroot --xid "$S_CONTEXT" \
-    -- "${INITCMD_STOP_SYNC[@]}" || :
+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" \
     ${USE_VNAMESPACE:+$_VNAMESPACE --enter "$S_CONTEXT"} \
     $_CHCONTEXT_COMPAT    "${CHCONTEXT_OPTS[@]}" \
-    "$_CAPCHROOT"    "${CAPCHROOT_OPTS[@]}" . "${INITCMD_STOP[@]}" && \
-    "${INITCMD_STOP_SYNC[@]}" || :
+    "$_CAPCHROOT"    "${CAPCHROOT_OPTS[@]}" "." \
+    "${INITCMD_STOP[@]}" && "${INITCMD_STOP_SYNC[@]}" || :
 fi
 
 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" || :