Create helper functions to start a guest that just sleeps and kills.
authorDaniel Hokka Zakrisson <daniel@hozac.com>
Thu, 25 Oct 2007 00:23:55 +0000 (00:23 +0000)
committerDaniel Hokka Zakrisson <daniel@hozac.com>
Thu, 25 Oct 2007 00:23:55 +0000 (00:23 +0000)
git-svn-id: http://svn.linux-vserver.org/svn/util-vserver/trunk@2628 94cd875c-1c1d-0410-91d2-eb244daf1a30

distrib/debian/initpost
distrib/redhat/initpost
scripts/vserver
scripts/vserver-build.functions
scripts/vserver.stop

index a5337c0..ccb6cab 100755 (executable)
@@ -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
index 4157a2b..3344dbb 100755 (executable)
@@ -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 || :
index da3fbe2..ab8dfa1 100755 (executable)
@@ -37,9 +37,10 @@ $"Usage: $(basename $0) [-s|--sync] [-v|--verbose] [--silent]
 <vserver> is the name of a vserver.
 
 Possible commands are:
-    start [--rescue [--rescue-init]] [<rescue-cmd> <args>*]
+    start [--rescue [--rescue-init] <rescue-cmd> <args>*]]
                 ... 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
index 3508f3f..f94a6aa 100644 (file)
@@ -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
+}
index 7f6cf2b..6c877a4 100644 (file)
@@ -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