X-Git-Url: http://git.linux-vserver.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=util-vserver%2Fscripts%2Ffunctions;h=df8129fa5e8c6d8e13e35c28c4206a7417a725db;hb=4fc0d7c31dd9fb6bae2e77ba37d8a08ab26dd65c;hp=655427a1db14a4c6e80b5f1a4e170fc8bc02dfd9;hpb=ac67e993c261ae4bce7570d52d937533b75d3d51;p=util-vserver.git diff --git a/util-vserver/scripts/functions b/util-vserver/scripts/functions index 655427a..df8129f 100644 --- a/util-vserver/scripts/functions +++ b/util-vserver/scripts/functions @@ -15,6 +15,10 @@ # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +_VS_NEWLINE=' +' +declare -r _VS_NEWLINE=${_VS_NEWLINE:0-1} + function findObject { local mod=$1 @@ -46,6 +50,19 @@ function findDir findObject -d "$@" } +function findAndCopy +{ + local dst=$1 + test ! -s "$dst" || return 0 + + local tmp + shift + findFile tmp "$@" + + test "$tmp" -a -s "$tmp" || return 0 + cp -af "$tmp" "$dst" +} + function getPhysicalDir { ( set -P && cd "$1" && pwd ) @@ -61,9 +78,21 @@ function _pkgMountBindDir() function _pkgSetVarsBase { case "$vserver" in - /*) - echo "not supported yet" - exit 1 + ./*|/*) + if test -d "$vserver/vdir"; then + BASEDIR=$vserver + VDIR=$(getPhysicalDir "$vserver/vdir") + + PKGDIR=$BASEDIR/apps/pkgmgmt + test -d "$PKGDIR" || { + echo "Can not find configuration-directory for package-managment tools" + exit 1 + } + findDir EXECDIR $PKGDIR/execdir / + else + VDIR=$(getPhysicalDir "$vserver") + PKGDIR= + fi ;; *) BASEDIR=$CONFDIR/$vserver @@ -96,39 +125,38 @@ function _pkgSetVarsBase function _pkgSetVarsRPM { - case "$vserver" in - /*) - echo "not supported yet" - exit 1 - ;; - - *) - findDir RPMETCDIR $PKGDIR/rpmetc $PKGDIR/base/rpm/etc /etc/rpm - findDir RPMSTATEDIR $PKGDIR/rpmstate $PKGDIR/base/rpm/state + if test "$PKGDIR"; then + findDir RPMETCDIR $PKGDIR/rpmetc $PKGDIR/base/rpm/etc /etc/rpm + findDir RPMSTATEDIR $PKGDIR/rpmstate $PKGDIR/base/rpm/state - findDir RPMLIBDIR $PKGDIR/rpmlib / + findDir RPMLIBDIR $PKGDIR/rpmlib / - RPMSTATEDIR=$(getPhysicalDir "$RPMSTATEDIR") - RPMETCDIR=$(getPhysicalDir "$RPMETCDIR") - ;; - esac + else + findDir RPMETCDIR "$VDIR"/etc/rpm /etc/rpm + findDir RPMSTATEDIR "$VDIR"/var/lib/rpm + RPMLIBDIR=/ + fi + + RPMSTATEDIR=$(getPhysicalDir "$RPMSTATEDIR") + RPMETCDIR=$(getPhysicalDir "$RPMETCDIR") } function _pkgSetVarsApt { - case "$vserver" in - /*) - echo "not supported yet" - exit 1 - ;; - - *) - findDir APTETCDIR $PKGDIR/aptetc $PKGDIR/base/apt/etc /etc/apt - findDir APTSTATEDIR $PKGDIR/aptstate $PKGDIR/base/apt/state - findDir APTCACHEDIR $PKGDIR/aptcache $PKGDIR/base/apt/cache - findDir APTARCHIVDIR $PKGDIR/aptarchives $PKGDIR/base/apt/archives /var/cache/apt/archives - ;; - esac + if test "$PKGDIR"; then + findDir APTETCDIR $PKGDIR/aptetc $PKGDIR/base/apt/etc /etc/apt + findDir APTSTATEDIR $PKGDIR/aptstate $PKGDIR/base/apt/state + findDir APTCACHEDIR $PKGDIR/aptcache $PKGDIR/base/apt/cache + findDir APTARCHIVDIR $PKGDIR/aptarchives $PKGDIR/base/apt/archives /var/cache/apt/archives + else + findDir APTETCDIR "$VDIR"/etc/apt /etc/apt + findDir APTSTATEDIR "$VDIR"/var/state/apt + findDir APTCACHEDIR "$VDIR"/var/cache/apt + findDir APTARCHIVDIR "$VDIR"/var/cache/apt/archives /var/cache/apt/archives + fi + + findFile APT_CONFIG "$APTETCDIR"/apt.conf "" + test -z "$APT_CONFIG" || export APT_CONFIG } function _pkgMountBase @@ -146,7 +174,7 @@ function _pkgMountRPM _pkgMountBindDir "$RPMETCDIR" /etc/rpm test "$RPMLIBDIR" = "/" || _pkgMountBindDir "$RPMLIBDIR" /usr/lib/rpm - "$_SECURE_MOUNT" "$VDIR" "$RPMSTATEDIR" "$_rpmdb_mntpoint" + "$_SECURE_MOUNT" --chroot "$VDIR" -n --secure --bind "$RPMSTATEDIR" "$_rpmdb_mntpoint" test -z "$WORKAROUND_106057" || mount -n --bind "$RPMSTATEDIR" "$_rpmdb_mntpoint" } @@ -212,13 +240,101 @@ function pkgInit function getAllVservers { local i - local var=$1 + declare -a _tmp=() for i in $CONFDIR/*; do test -d "$i" || continue test ! -e "$i"/disabled || continue test -d "$i"/vdir || continue + case "$i" in + *.~*~) continue;; + esac + + _tmp=( "${_tmp[@]}" "${i##$CONFDIR/}") + done + + eval $1='( "${_tmp[@]}" )' +} - eval "$var=\"$var ${i##$CONFDIR/}\"" +## Usage: getVserverCtx [ []] +function getVserverStatus +{ + test -r "$1"/run || return 1 + + local _ctx + read _ctx <"$1"/run + eval "$2"=\$_ctx + + test "$3" || return 0 + local _tmp=$($_VPS ax | $_AWK '{print $2}' | $_GREP -x "$_ctx" | $_WC -l ) + eval "$3"=\$_tmp + + test "$4" -a $_tmp = 0 || return 0 + _tmp=$(readlink "$1/run") + test "$_tmp" || return 1 + rm -f "$_tmp" + return 0 +} + +## Usage: isCtxRunning +function isCtxRunning +{ + local _tmp=$($_VPS ax | $_AWK '{print $2}' | $_GREP -x "$1" | $_WC -l ) + test $_tmp -gt 0 +} + +## Usage: isVserverRunning [] +function isVserverRunning +{ + local ctx procnum + + getVserverStatus "$1" ctx procnum 1 || return 1 + test $procnum != 0 || return 1 + test -z "$2" || eval "$2"=\$ctx + return 0 +} + +## Called as 'getFileValue ' +function getFileValue +{ + test -r "$2" || return 0 + eval read "$1" <"$2" +} + +## Called as 'getFileArray ' +function getFileArray +{ + test -r "$2" || return 0 + + local IFS=$_VS_NEWLINE + eval "$1"='( $(< "$2") )' +} + +function checkComponents +{ + local i + local msg=$1 + local x_failed= + + shift + + for i; do + local failed= + case "$i" in + core) test -x "$_CHBIND" || failed=1;; + build) test -x "$_VSERVER_BUILD" || failed=1;; + sysv) test -x "$INITRDDIR/vserver" || failed=1;; + devel) test -d "$INCLUDEDIR/vserver.h" || failed=1;; + *) echo "Unknown component '$i'" + return false + ;; + esac + + test -z "$failed" || { + echo "$msg: $i" + x_failed=1 + } done + + test -z "$x_failed" }