util-vserver 0.30.215.
[util-vserver.git] / scripts / vserver-build.functions
index 38e6380..c8ccb84 100644 (file)
@@ -1,4 +1,4 @@
-# $Id: vserver-build.functions 2315 2006-09-15 19:16:48Z hollow $      --*- sh -*--
+# $Id: vserver-build.functions 2704 2008-03-16 03:30:22Z dhozac $      --*- sh -*--
 
 # Copyright (C) 2003 Enrico Scholz <enrico.scholz@informatik.tu-chemnitz.de>
 #  
@@ -54,7 +54,8 @@ function populateDev
 {
     local spec
 
-    mkdir -p -m755 "$VDIR"/dev/pts
+    mkdir -p -m755 "$VDIR"/dev
+    mkdir -m755 "$VDIR"/dev/pts
 
     while read spec; do
        makeDevEntry "$VDIR"/dev $spec
@@ -112,7 +113,7 @@ function _setCacheDir
     }
 }
 
-function _setVserverDir
+function _setVserverDirName
 {
     test -z "$VSERVERDIRNAME" || return 0
     VSERVERDIRNAME="$VSERVER_NAME"
@@ -183,6 +184,8 @@ ERROR: Can not determine distribution; please specify it manually with
 ERROR: Can not find configuration for the distribution '$DISTRIBUTION';
   please read http://linux-vserver.org/HowToRegisterNewDistributions
   for information how to add support for your own distribution."
+
+    export DISTRIBUTION
 }
 
 function base._addGeneratedFile
@@ -200,6 +203,9 @@ exist already; please try to use '--force', or remove them manually."
 
     mkdir -p -m755 "$VDIR"
     $_SETATTR --~barrier "$VDIR"
+    $_SETATTR --barrier "$VDIR"/.. || colwarn $"\
+WARNING: could not set the barrier attribute on '$VDIR/..',
+         please set it manually."
     base._addGeneratedFile "$VDIR"
     
     mkdir -p -m755 "$SETUP_CONFDIR"/apps "$VDIR"/etc
@@ -223,7 +229,7 @@ function base._initVariables
 {
     _setRootDir
     _setCacheDir
-    _setVserverDir
+    _setVserverDirName
     _setVdir
 
     findFile _DEV_FILE      "$__CONFDIR/.distributions/$DISTRIBUTION/devs"      "$__DISTRIBDIR/$DISTRIBUTION/devs"     "$__DISTRIBDIR/defaults/devs"
@@ -254,3 +260,27 @@ function base.setSuccess
 {
     __BASE_SUCCESS=1
 }
+
+function startSleepingGuest
+{
+    local guest="$1"
+    local timeout="${2:-15}"
+    $_VSERVER "$guest" start --rescue --rescue-init bash -c "
+       exec  > /dev/null
+       exec 2> /dev/null
+       trap 'kill -s 9 -- -1; exit 0' INT
+       i=0
+       while [ \$i -lt $timeout ]; do
+           sleep 1
+           let ++i
+       done
+       kill -s 15 -- -1
+       sleep 1
+       kill -s 9 -- -1"
+}
+
+function stopSleepingGuest
+{
+    local guest="$1"
+    $_VSERVER "$guest" stop --rescue-init
+}