[vserver] dlimit refresher script for review :)

From: Ghislain <gadnet_at_aqueos.com>
Date: Mon 27 Feb 2012 - 23:13:46 GMT
Message-ID: <4F4C0E2A.8090705@aqueos.com>


   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:


# 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" ]];
         echo "No guest of that name";
         exit 10 ;
         # pas de vserver de ce nom

# 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" ]];
                 INODES=`cat "$repertoire/inodes_total"`;
                 if [[ $USED_INODES -lt $INODES ]];
                         # limit is greater than usage we can enforce it
                         vdlimit --xid "$1" -s
inodes_total="$INODES" "$DIRECTORY";
                         echo "ALERTE: inodes usage > limit:

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

         if [[ -e "$repertoire/space_total" ]];
                 SPACE=`cat "$repertoire/space_total"`;

                 if [[ $USED_SPACE -lt $SPACE ]];
                         # limit is greater than usage we can enforce it
                         vdlimit --xid "$1" -s
space_total="$SPACE" "$DIRECTORY";
                         echo "ALERTE: espace usage > limit:

         # refresh the xid of this directory
         # U skip unified/hashified files, R recurse, x do not cross
         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";

    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 :)


Received on Mon Feb 27 23:14:33 2012
[Next/Previous Months] [Main vserver Project Homepage] [Howto Subscribe/Unsubscribe] [Paul Sladen's vserver stuff]
Generated on Mon 27 Feb 2012 - 23:14:34 GMT by hypermail 2.1.8