# 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
{
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
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
}
function _pkgMountBase
_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"
}
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
- eval "$var=\"$var ${i##$CONFDIR/}\""
+ tmp=( "${tmp[@]}" "${i##$CONFDIR/}")
done
+
+ eval $1=\$tmp
+}
+
+## Usage: getVserverCtx <vdir> <result-varname> [<procnumber-varname> [<do-cleanup>]]
+function getVserverStatus
+{
+ test -r "$1"/run || return 1
+ eval read "$2" <"$1"/run
+
+ 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: isVserverRunning <vdir> [<ctx-varname>]
function isVserverRunning
{
- local vdir=$1
- test -r "$vdir/run" || return 1
+ local ctx procnum
- local ctx
- read ctx <"$vdir"/run || { echo "Failed to read ctx information" >&2; return 0; }
-
- local cnt=$($_VPS ax | $_AWK '{print $2}' | $_GREP -x "$ctx" | $_WC -l )
+ getVserverStatus "$1" ctx procnum 1 || return 1
+ test $procnum != 0 || return 1
+ test -z "$2" || eval "$2"=\$ctx
+ return 0
+}
- if test $cnt = 0; then
- ## Remove old lock-file
- rm -f $(readlink "$vdir/run")
- return 1
- else
- return 0
- fi
+## Called as 'getFileValue <varname> <filename>'
+function getFileValue
+{
+ test -r "$2" || return 0
+ eval read "$1" <"$2"
+}
+
+## Called as 'getFileArray <varname> <filename>'
+function getFileArray
+{
+ test -r "$2" || return 0
+
+ local IFS=$_VS_NEWLINE
+ eval "$1"='( $(< "$2") )'
}