X-Git-Url: http://git.linux-vserver.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=util-vserver%2Fscripts%2Fvshelper;h=2bd6ed16b24ae107a45af0a607d1db684d3a9020;hb=cc0e846b03b1250540445dd1f92083ee338898a2;hp=1d589075b6f37d5c2d17b30056d1fc2b7df716a0;hpb=552047c69c293485ce2401ae8bc0c0894b2fb410;p=util-vserver.git diff --git a/util-vserver/scripts/vshelper b/util-vserver/scripts/vshelper index 1d58907..2bd6ed1 100755 --- a/util-vserver/scripts/vshelper +++ b/util-vserver/scripts/vshelper @@ -1,4 +1,4 @@ -#! /bin/bash +#! /usr/lib/util-vserver/sigexec /bin/bash # Copyright (C) 2004 Enrico Scholz # @@ -19,7 +19,7 @@ : ${UTIL_VSERVER_VARS:=/usr/lib/util-vserver/util-vserver-vars} test -e "$UTIL_VSERVER_VARS" || { - echo "Can not find util-vserver installation; aborting..." >&2 + echo $"Can not find util-vserver installation (the file '$UTIL_VSERVER_VARS' would be expected); aborting..." >&2 exit 1 } . "$UTIL_VSERVER_VARS" @@ -54,11 +54,13 @@ function doInternalMethod case "$ACTION" in (restart) logging $"Restarting vserver '$VSERVER'" - execute $_VSERVER "$VSERVER" restart + spawn killContext "$XID" + execute $_VSERVER --defaulttty "$VSERVER" restart ;; (halt|poweroff) logging $"Stopping vserver '$VSERVER'" - execute $_VSERVER "$VSERVER" stop + spawn killContext "$XID" + execute $_VSERVER --defaulttty "$VSERVER" stop ;; (swsusp) ## TODO: any senseful action here? Perhaps shutdown scheduler for it? @@ -70,23 +72,28 @@ function doInternalMethod exit 1 esac ;; + + (async) + spawn killContext "$XID" + ;; (sync) local f=${METHOD_ARGS[0]} - test "$f" || + test -n "$f" || panic $"Insufficent arguments for method '$method' and vserver '$VSERVER'" test -p "$f" || panic $"File '$f' which is required for synchronisation of vserver '$VSERVER' is not a pipe" + spawn killContext "$XID" echo "$ACTION" >"$f" ;; (*) local script - findObject -x script "$CONFDIR"/.defaults/apps/vshelper-methods/"$method" "$PKGLIBDIR"/vshelper-methods/"$method" '' + findObject -x script "$__CONFDIR"/.defaults/apps/vshelper-methods/"$method" "$__PKGLIBDIR"/vshelper-methods/"$method" '' - test '$script' || { + test -n '$script' || { warning $"No handler for internal method '$method' found" exit 1 } @@ -113,42 +120,56 @@ function doDefaultMethod #=========== +test "$1" != '--version' || showVersion +test "$1" != '--help' || showHelp + if ! tty -s; then - findObject -e _VS_LOGFILE "$CONFDIR"/.defaults/apps/vshelper/logfile /dev/null - findObject -e _VS_ERRFILE "$CONFDIR"/.defaults/apps/vshelper/logfile /dev/null + findObject -e _VS_LOGFILE "$__CONFDIR"/.defaults/apps/vshelper/logfile /dev/null + findObject -e _VS_ERRFILE "$__CONFDIR"/.defaults/apps/vshelper/logfile /dev/null + exec >$_VS_LOGFILE exec 2>>$_VS_ERRFILE fi - -logging "$(date): vshelper $*" -test "$1" != '--version' || showVersion -test "$1" != '--help' || showHelp +logging "$(date): vshelper $*" + test "$#" -ge 2 || panic $"vshelper called with missing arguments; try '--help' for more information" + vshelper.isEnabled || exit 0 +! vshelper.isDebug || set -x set -eu -declare -r XID=$1 -declare -r ACTION=$2 +if $_VSERVER_INFO - FEATURE vshelper0; then + declare -r XID=$1 + declare -r ACTION=$2 +elif $_VSERVER_INFO - FEATURE vshelper; then + declare -r ACTION=$1 + declare -r XID=$2 +else + panic $"vshelper functionality not supported by kernel" +fi +findObject -x delegate "$__CONFDIR"/.defaults/apps/vshelper-delegate/"$ACTION" "$__PKGLIBDIR"/vshelper-delegate/"$ACTION" '' +test -e "$delegate" && exec -a "$ACTION" "$delegate" "$@" this_xid=$($_VSERVER_INFO - XID) pxid= +responsible_xid=$XID while true; do - pxid=$($_VSERVER_INFO "$XID" PXID) || break - test "$pxid" -ne "$this_xid" || break - xid=$pxid + pxid=$($_VSERVER_INFO "$responsible_xid" PXID) || break + test "$pxid" -ne "$this_xid" || break + responsible_xid=$pxid done -vserver_id=$($_VSERVER_INFO "$XID" ID) || - panic $"No responsible vserver found for xid '$1' ($XID); aborting..." +vserver_id=$($_VSERVER_INFO "$responsible_xid" ID) || + panic $"No responsible vserver found for xid '$responsible_xid' ($XID); aborting..." -test "$1" = "$XID" || { - logging "Giving 'vshelper' task for '$1' to parent vserver '$vserver_id' ($XID)" +test "$XID" = "$responsible_xid" || { + logging "Giving 'vshelper' task for '$XID' to parent vserver '$vserver_id' ($responsible_xid)" execute $_VSERVER "$vserver_id" exec $_VSHELPER "$@" } @@ -157,7 +178,7 @@ test "$1" = "$XID" || { ARGS=( "$@" ) declare -a state -getFileArray state "$VSHELPERSTATEDIR/$XID" && test ${#state[@]} -ge 2 || { +getFileArray state "$__VSHELPERSTATEDIR/$XID" && test ${#state[@]} -ge 2 || { logging "'vshelper' not configured for xid '$XID'" exit 0 }