From bb037facbbc44938ffe0151941786ef959c48008 Mon Sep 17 00:00:00 2001 From: Ionescu Bogdan Date: Thu, 3 Dec 2015 03:00:06 +0200 Subject: [PATCH 1/2] Update v-add-sys-quota - Supports journaled quotas (version 2 quota) - Journaled quotas have the advantage that even after a crash no quota check is required - Quotacheck on reboot --- bin/v-add-sys-quota | 47 ++++++++++++++++++++++++++------------------- 1 file changed, 27 insertions(+), 20 deletions(-) diff --git a/bin/v-add-sys-quota b/bin/v-add-sys-quota index 10432a60..b831e7bf 100755 --- a/bin/v-add-sys-quota +++ b/bin/v-add-sys-quota @@ -1,12 +1,12 @@ #!/bin/bash # info: add system quota -# opions: NONE +# options: NONE # # The script enables filesystem quota on /home patition #----------------------------------------------------------# -# Variable&Function # +# Variable & Function # #----------------------------------------------------------# # Includes @@ -19,7 +19,8 @@ source $VESTA/conf/vesta.conf #----------------------------------------------------------# # Checking quota package -if [ ! -e "/usr/sbin/setquota" ]; then +quota=$(which --skip-alias --skip-functions quota 2>/dev/null) +if [ $? -ne 0 ]; then if [ -e "/etc/redhat-release" ]; then yum -y install quota >/dev/null 2>&1 check_result $? "quota package installation failed" $E_UPDATE @@ -35,34 +36,40 @@ fi # Action # #----------------------------------------------------------# -# Adding usrquota option on /home partition -mnt=$(df -P /home |awk '{print $6}' |tail -n1) -lnr=$(cat -n /etc/fstab |awk '{print $1,$3}' |grep "$mnt$" |cut -f 1 -d ' ') -options=$(sed -n ${lnr}p /etc/fstab |awk '{print $4}') -if [ -z "$(echo $options |grep usrquota)" ]; then - sed -i "$lnr s/$options/$options,usrquota/" /etc/fstab +# Adding group and user quota on /home partition +mnt=$(df -P /home | awk '{print $6}' | tail -n1) +lnr=$(cat -n /etc/fstab | awk '{print $1,$3}' | grep "$mnt$" | cut -f 1 -d ' ') +opt=$(sed -n ${lnr}p /etc/fstab | awk '{print $4}') +fnd='usrquota\|grpquota\|usrjquota=aquota.user\|grpjquota=aquota.group\|jqfmt=vfsv0' +if [ $(echo $opt | tr ',' '\n' | grep -x $fnd | wc -l) -ne 5 ]; then + old=$(echo $(echo $opt | tr ',' '\n' | grep -v 'usrquota\|grpquota\|usrjquota=\|grpjquota=\|jqfmt=') | tr ' ' ',') + new='usrquota,grpquota,usrjquota=aquota.user,grpjquota=aquota.group,jqfmt=vfsv0' + sed -i "$lnr s/$opt/$old,$new/" /etc/fstab mount -o remount $mnt fi -# Adding aquota.user file -if [ ! -e "$mnt/aquota.user" ]; then - quotacheck -cu $mnt >/dev/null 2>&1 +# Adding v2 group and user quota index +if [ ! -e "$mnt/aquota.user" ] || [ ! -e "$mnt/aquota.group" ]; then + quotaoff $mnt + quotacheck -cug $mnt >/dev/null 2>&1 + quotacheck -aug >/dev/null 2>&1 fi -# Building fs quota index -quotacheck -um $mnt +# Adding quotacheck on reboot +touch /forcequotacheck -# Adding weekly cron job -echo "quotacheck -um $mnt" > /etc/cron.daily/quotacheck +# Adding cron job +echo '#!/bin/bash' > /etc/cron.daily/quotacheck +echo 'touch /forcequotacheck' >> /etc/cron.daily/quotacheck chmod a+x /etc/cron.daily/quotacheck -# Enabling fs quota -if [ ! -z "$(quotaon -pa|grep " $mnt "|grep user|grep 'off')" ]; then +# Enabling group and user quota +if [ ! -z "$(quotaon -pa | grep " $mnt " | grep 'user\|group' | grep 'is off')" ]; then quotaon $mnt - check_result $? "quota can't be enabled in $mtn" $E_DISK + check_result $? "quota can't be enabled in $mnt" $E_DISK fi -# Updating DISK_QUOTA value +# Updating vesta.conf value if [ -z "$(grep DISK_QUOTA $VESTA/conf/vesta.conf)" ]; then echo "DISK_QUOTA='yes'" >> $VESTA/conf/vesta.conf else From 04f497d9329a17eaaed2685190435cd7400b4caa Mon Sep 17 00:00:00 2001 From: Ionescu Bogdan Date: Thu, 3 Dec 2015 03:08:36 +0200 Subject: [PATCH 2/2] Update v-delete-sys-quota - minor updates - see: v-add-sys-quota --- bin/v-delete-sys-quota | 39 ++++++++++++++++++++++----------------- 1 file changed, 22 insertions(+), 17 deletions(-) diff --git a/bin/v-delete-sys-quota b/bin/v-delete-sys-quota index 13f23e9c..61d18faa 100755 --- a/bin/v-delete-sys-quota +++ b/bin/v-delete-sys-quota @@ -1,12 +1,12 @@ #!/bin/bash # info: delete system quota -# opions: NONE +# options: NONE # # The script disables filesystem quota on /home patition #----------------------------------------------------------# -# Variable&Function # +# Variable & Function # #----------------------------------------------------------# # Includes @@ -23,29 +23,34 @@ source $VESTA/conf/vesta.conf # Action # #----------------------------------------------------------# -# Deleting usrquota on /home partition -mnt=$(df -P /home |awk '{print $6}' |tail -n1) -lnr=$(cat -n /etc/fstab |awk '{print $1,$3}' |grep "$mnt$" |cut -f 1 -d ' ') -options=$(sed -n ${lnr}p /etc/fstab |awk '{print $4}') -if [ ! -z "$(echo $options |grep usrquota)" ]; then - sed -i "$lnr s/,usrquota//" /etc/fstab +# Deleting group and user quota on /home partition +mnt=$(df -P /home | awk '{print $6}' | tail -n1) +lnr=$(cat -n /etc/fstab | awk '{print $1,$3}' | grep "$mnt$" | cut -f 1 -d ' ') +opt=$(sed -n ${lnr}p /etc/fstab | awk '{print $4}') +fnd='usrquota\|grpquota\|usrjquota=\|grpjquota=\|jqfmt=' +if [ ! -z "$(echo $opt | grep $fnd)" ]; then + rep=$(echo $(echo $opt | tr ',' '\n' | grep -v $fnd) | tr ' ' ',') + sed -i "$lnr s/$opt/$rep/" /etc/fstab mount -o remount $mnt fi -# Disabling fs quota -if [ -z "$(quotaon -pa|grep " $mnt "|grep user|grep 'off')" ]; then - quotaoff $mnt +# Disabling group and user quota +quotaoff=$(which --skip-alias --skip-functions quotaoff 2>/dev/null) +if [ $? -eq 0 ]; then + if [ ! -z "$(quotaon -pa | grep " $mnt " | grep 'user\|group' | grep 'is on')" ]; then + $quotaoff $mnt + fi fi -# Deleting quota index -if [ -e "$mnt/aquota.user" ]; then - rm $mnt/aquota.user -fi +# Deleting v1 + v2 group and user quota index +for idx in $(echo 'quota.user quota.group aquota.user aquota.group'); do + [ -e "$mnt/$idx" ] && rm -f $mnt/$idx +done -# Deleting weekly cron job +# Deleting cron job rm -f /etc/cron.daily/quotacheck -# Updating DISK_QUOTA value +# Updating vesta.conf value if [ -z "$(grep DISK_QUOTA $VESTA/conf/vesta.conf)" ]; then echo "DISK_QUOTA='no'" >> $VESTA/conf/vesta.conf else