Subject: dlimit refresher script for review :)
From: Ghislain <gadnet@aqueos.com>
Date: Tue, 28 Feb 2012 00:13:46 +0100
Tue, 28 Feb 2012 00:13:46 +0100
hi,

   i had a problem with dlimit being out of sync with the values i set 
for them in /etc/vserver and the reality. I wrote a tiny script that 
will scan the dlimit you set and adjust the real limit and the real 
usage for each guest. I would want to share for comment here before 
adding it to the wiki to see if anyone have idea of improvement or tell 
me  if i done something silly:


#!/bin/bash

# Which vserver we look at and what is the config directory
# (c) AQUEOS , you can freely use this script but AQUEOS will not be 
liable for any damage it could done. Use it at your own risk.
# mean to be launched like this:  dlimit-refresh.sh <guest name>   OR   
vsomething dlimit-refresh.sh -- --all --
#

CFGDIR=`vserver-info "$1" CFGDIR`;

if [[ ! -d "$CFGDIR" ]];
then
         echo "No guest of that name";
         exit 10 ;
         # pas de vserver de ce nom
fi


# pour chaque repertoire dans /etc/vservers/xxxx/dlimits/
# lire le repertoire concerne et raffraichir ses limites
for repertoire in $( ls -d $CFGDIR/dlimits/* ); do
         # learn directory path
         DIRECTORY=$(cat "$repertoire/directory");
         # see the actual usage in inode and space .. can take time ...
         USED SPACE=$(vdu --xid "$1"      --space  "$DIRECTORY" | cut 
-d" " -f2);
         USED INODES=$(vdu --xid "$1"      --inodes "$DIRECTORY" | cut 
-d" " -f2);

         if [[ -e "$repertoire/inodes total" ]];
         then
                 INODES=`cat "$repertoire/inodes total"`;
                 if [[ $USED INODES -lt $INODES ]];
                 then
                         # limit is greater than usage we can enforce it
                         vdlimit --xid "$1" -s 
inodes total="$INODES"              "$DIRECTORY";
                 else
                         echo "ALERTE: inodes usage > limit:  
$USED INODES > $INODES";
                 fi
         fi

         if [[ -e "$repertoire/reserved" ]];
         then
                 RESERVED=`cat "$repertoire/reserved"`;
                 vdlimit --xid "$1" -s 
reserved="$RESERVED"                "$DIRECTORY";
         fi

         if [[ -e "$repertoire/space total" ]];
         then
                 SPACE=`cat "$repertoire/space total"`;

                 if [[ $USED SPACE -lt $SPACE ]];
                 then
                         # limit is greater than usage we can enforce it
                         vdlimit --xid "$1" -s 
space total="$SPACE"                "$DIRECTORY";
                 else
                         echo "ALERTE: espace usage > limit:  
$USED INODES > $INODES";
                 fi
         fi

         # refresh the  xid of this directory
         # U skip unified/hashified files, R recurse, x do not cross 
filesystems
         chxid -URx -c "$1" "$DIRECTORY";

         # refresh the usage with the actual limits
         vdlimit --xid "$1" -s space used=$USED SPACE   "$DIRECTORY";
         vdlimit --xid "$1" -s inodes used=$USED INODES "$DIRECTORY";

         # print the result
         vdlimit --xid "$1"  "$DIRECTORY";
done



    Sorry for the part in french in the comment. Hope that can help 
someone and perhaps someone will telll me that a tool do allready this 
as i discover regulary that vserver-utils have plenty of hidden treasures :)


Regards,
Ghislain.



["application/pkcs7-signature" not shown]