From e73af524ef22868d4980ae13430c205798603c41 Mon Sep 17 00:00:00 2001 From: Daniel Hokka Zakrisson Date: Thu, 25 Oct 2007 00:23:55 +0000 Subject: [PATCH] Create helper functions to start a guest that just sleeps and kills. git-svn-id: http://svn.linux-vserver.org/svn/util-vserver/trunk@2628 94cd875c-1c1d-0410-91d2-eb244daf1a30 --- distrib/debian/initpost | 18 +++--------------- distrib/redhat/initpost | 18 +++--------------- scripts/vserver | 5 +++-- scripts/vserver-build.functions | 19 +++++++++++++++++++ scripts/vserver.stop | 8 ++++++++ 5 files changed, 36 insertions(+), 32 deletions(-) diff --git a/distrib/debian/initpost b/distrib/debian/initpost index a5337c0..ccb6cab 100755 --- a/distrib/debian/initpost +++ b/distrib/debian/initpost @@ -21,6 +21,7 @@ cfgdir="$1" vdir="$cfgdir"/vdir . "$2" +. "$_LIB_VSERVER_BUILD_FUNCTIONS" # vserver name @@ -109,19 +110,7 @@ echo # start vserver before we can exec anything inside it $_VSERVER "$NAME" stop &>/dev/null || : -$_VSERVER "$NAME" start --rescue --rescue-init bash -c ' - exec > /dev/null - exec 2> /dev/null - - set -x - f=/tmp/startwait - trap "rm -f $f" EXIT - mkfifo $f - ( sleep 15; kill -s 9 -- -1 ) & - cat "$f" - kill -s 9 -- -1 - wait -' +startSleepingGuest "$NAME" 30 # run the configure commands from within the server export LANG=C LC_ALL=C @@ -139,7 +128,6 @@ for i in bootlogd checkfs checkroot halt hwclock.sh ifupdown klogd \ done # stop the vserver -$_VSERVER "$NAME" exec bash -c ': >/tmp/startwait' &>/dev/null || : -$_VSERVER "$NAME" stop &>/dev/null || : +stopSleepingGuest "$NAME" &>/dev/null || : popd &>/dev/null diff --git a/distrib/redhat/initpost b/distrib/redhat/initpost index 4157a2b..3344dbb 100755 --- a/distrib/redhat/initpost +++ b/distrib/redhat/initpost @@ -19,6 +19,7 @@ vdir=$1/vdir . "$2" +. "$_LIB_VSERVER_BUILD_FUNCTIONS" function relink { @@ -44,19 +45,7 @@ vserver=$1 ## Do some magic to set the vserver into a defined state $_VSERVER "$vserver" stop &>/dev/null || : -$_VSERVER "$vserver" start --rescue --rescue-init bash -c ' - exec >/dev/null - exec 2>/dev/null - - set -x - f=/tmp/startwait - trap "rm -f $f" EXIT - mkfifo $f - ( sleep 15; kill -s 9 -- -1 ) & - cat "$f" >/dev/null - kill -s 9 -- -1 - wait -' +startSleepingGuest "$vserver" 15 pushd "$vdir"/etc/init.d &>/dev/null || pushd "$vdir"/etc/rc.d/init.d &>/dev/null || exit 1 @@ -102,5 +91,4 @@ EOF s!si::sysinit:/etc/rc.d/rc.sysinit!si::sysinit:/etc/rc.d/rc.sysinit.vserver!' popd >/dev/null -$_VSERVER "$vserver" exec bash -c ': >/tmp/startwait' &>/dev/null || : -$_VSERVER "$vserver" stop &>/dev/null || : +stopSleepingGuest "$vserver" &> /dev/null || : diff --git a/scripts/vserver b/scripts/vserver index da3fbe2..ab8dfa1 100755 --- a/scripts/vserver +++ b/scripts/vserver @@ -37,9 +37,10 @@ $"Usage: $(basename $0) [-s|--sync] [-v|--verbose] [--silent] is the name of a vserver. Possible commands are: - start [--rescue [--rescue-init]] [ *] + start [--rescue [--rescue-init] *]] ... starts the specified vserver - stop ... stops the specified vserver + stop [--rescue-init] + ... stops the specified vserver restart ... restarts the specified vserver; this is the subsequent execution of a synchronized 'stop' and a 'start' condrestart ... restarts the vserver when it is running already diff --git a/scripts/vserver-build.functions b/scripts/vserver-build.functions index 3508f3f..f94a6aa 100644 --- a/scripts/vserver-build.functions +++ b/scripts/vserver-build.functions @@ -256,3 +256,22 @@ function base.setSuccess { __BASE_SUCCESS=1 } + +function startSleepingGuest +{ + local guest="$1" + local timeout="$2" + $_VSERVER "$guest" start --rescue --rescue-init bash -c " + exec > /dev/null + exec 2> /dev/null + sleep $timeout + kill -s 15 -- -1 + sleep 1 + kill -s 9 -- -1" +} + +function stopSleepingGuest +{ + local guest="$1" + $_VSERVER "$guest" stop --rescue-init +} diff --git a/scripts/vserver.stop b/scripts/vserver.stop index 7f6cf2b..6c877a4 100644 --- a/scripts/vserver.stop +++ b/scripts/vserver.stop @@ -48,6 +48,14 @@ trap "cleanup" EXIT OPTION_FORCE_SYNC=1 +while test "$#" -gt 0; do + case "$1" in + (--rescue-init) _IS_FAKEINIT=1;; + (--) shift; break;; + (-*) panic $"vserver ... stop: unknown option '$1'";; + esac +done + set -e generateOptions "$VSERVER_DIR" set +e -- 1.8.1.5