3 # Copyright (C) 2004 Enrico Scholz <enrico.scholz@informatik.tu-chemnitz.de>
5 # This program is free software; you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License as published by
7 # the Free Software Foundation; version 2 of the License.
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
14 # You should have received a copy of the GNU General Public License
15 # along with this program; if not, write to the Free Software
16 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18 ## Usage: vshelper <xid> <action> <args>
20 : ${UTIL_VSERVER_VARS:=/usr/lib/util-vserver/util-vserver-vars}
21 test -e "$UTIL_VSERVER_VARS" || {
22 echo "Can not find util-vserver installation; aborting..." >&2
25 . "$UTIL_VSERVER_VARS"
31 Usage: vshelper <xid> <event> <args>*
33 Report bugs to <$PACKAGE_BUGREPORT>."
40 vshelper $PACKAGE_VERSION -- userspace reboot helper
41 This program is part of $PACKAGE_STRING
43 Copyright (C) 2004 Enrico Scholz
44 This program is free software; you may redistribute it under the terms of
45 the GNU General Public License. This program has absolutely no warranty."
49 function doInternalMethod
56 logging $"Restarting vserver '$VSERVER'"
57 execute $_VSERVER "$VSERVER" restart
60 logging $"Stopping vserver '$VSERVER'"
61 execute $_VSERVER "$VSERVER" stop
64 ## TODO: any senseful action here? Perhaps shutdown scheduler for it?
69 warning $"Unknown action '$ACTION' for vserver '$VSERVER'"
75 local f=${METHOD_ARGS[0]}
77 panic $"Insufficent arguments for method '$method' and vserver '$VSERVER'"
80 panic $"File '$f' which is required for synchronisation of vserver '$VSERVER' is not a pipe"
87 findObject -x script "$CONFDIR"/.defaults/apps/vshelper-methods/"$method" "$PKGLIBDIR"/vshelper-methods/"$method" ''
90 warning $"No handler for internal method '$method' found"
95 execute "$script" "${ARGS[@]}"
99 function doDefaultMethod
103 vshelper.getHandler handler "$VSERVER" "$ACTION" || {
104 warning $"No handler configured for action '$ACTION' on vserver '$VSERVER'"
109 (/*) execute "$handler" "${ARGS[@]}";;
110 (:*) doInternalMethod "${handler##:}" "$@";;
117 findObject -e _VS_LOGFILE "$CONFDIR"/.defaults/apps/vshelper/logfile /dev/null
118 findObject -e _VS_ERRFILE "$CONFDIR"/.defaults/apps/vshelper/logfile /dev/null
124 logging "$(date): vshelper $*"
126 test "$1" != '--version' || showVersion
127 test "$1" != '--help' || showHelp
129 panic $"vshelper called with missing arguments; try '--help' for more information"
131 vshelper.isEnabled || exit 0
139 this_xid=$($_VSERVER_INFO - XID)
142 pxid=$($_VSERVER_INFO "$XID" PXID) || break
143 test "$pxid" -ne "$this_xid" || break
147 vserver_id=$($_VSERVER_INFO "$XID" ID) ||
148 panic $"No responsible vserver found for xid '$1' ($XID); aborting..."
150 test "$1" = "$XID" || {
151 logging "Giving 'vshelper' task for '$1' to parent vserver '$vserver_id' ($XID)"
152 execute $_VSERVER "$vserver_id" exec $_VSHELPER "$@"
160 getFileArray state "$VSHELPERSTATEDIR/$XID" && test ${#state[@]} -ge 2 || {
161 logging "'vshelper' not configured for xid '$XID'"
165 declare -r VSERVER=${state[0]}
167 cfg_xid=$($_VSERVER_INFO "${state[0]}" CONTEXT false) ||
168 panic $"Configured vserver '$VSERVER' does not seem to run; aborting..."
170 test "$cfg_xid" = "$XID" ||
171 panic $"Configured ($cfg_xid) and actual ($XID) xid for vserver '$VSERVER' are mismatching; aborting..."
173 cur_xid=$($_VSERVER_INFO "$VSERVER" CONTEXT false) ||
174 panic $"Vserver '$VSERVER' with '$XID' does not seem to run; strange..."
176 test "$cur_xid" = "$XID" ||
177 panic $"Expected ($XID) and actual ($cur_xid) xid for vserver '$VSERVER' are mismatching; strange..."
181 if test "${#state[@]}" -gt 2; then
182 unset state[0] state[1]
183 declare -ra METHOD_ARGS=( "${state[@]}" )
185 declare -ra METHOD_ARGS=()
189 (default) doDefaultMethod "$@";;
190 (sync) doInternalMethod "$method" "$@";;
191 (*) panic $"Unknown method '$method' used by vserver '$VSERVER'";;