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
This commit is contained in:
Ionescu Bogdan 2015-12-03 03:00:06 +02:00
commit bb037facbb

View file

@ -1,12 +1,12 @@
#!/bin/bash #!/bin/bash
# info: add system quota # info: add system quota
# opions: NONE # options: NONE
# #
# The script enables filesystem quota on /home patition # The script enables filesystem quota on /home patition
#----------------------------------------------------------# #----------------------------------------------------------#
# Variable&Function # # Variable & Function #
#----------------------------------------------------------# #----------------------------------------------------------#
# Includes # Includes
@ -19,7 +19,8 @@ source $VESTA/conf/vesta.conf
#----------------------------------------------------------# #----------------------------------------------------------#
# Checking quota package # 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 if [ -e "/etc/redhat-release" ]; then
yum -y install quota >/dev/null 2>&1 yum -y install quota >/dev/null 2>&1
check_result $? "quota package installation failed" $E_UPDATE check_result $? "quota package installation failed" $E_UPDATE
@ -35,34 +36,40 @@ fi
# Action # # Action #
#----------------------------------------------------------# #----------------------------------------------------------#
# Adding usrquota option on /home partition # Adding group and user quota on /home partition
mnt=$(df -P /home |awk '{print $6}' |tail -n1) mnt=$(df -P /home | awk '{print $6}' | tail -n1)
lnr=$(cat -n /etc/fstab |awk '{print $1,$3}' |grep "$mnt$" |cut -f 1 -d ' ') 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}') opt=$(sed -n ${lnr}p /etc/fstab | awk '{print $4}')
if [ -z "$(echo $options |grep usrquota)" ]; then fnd='usrquota\|grpquota\|usrjquota=aquota.user\|grpjquota=aquota.group\|jqfmt=vfsv0'
sed -i "$lnr s/$options/$options,usrquota/" /etc/fstab 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 mount -o remount $mnt
fi fi
# Adding aquota.user file # Adding v2 group and user quota index
if [ ! -e "$mnt/aquota.user" ]; then if [ ! -e "$mnt/aquota.user" ] || [ ! -e "$mnt/aquota.group" ]; then
quotacheck -cu $mnt >/dev/null 2>&1 quotaoff $mnt
quotacheck -cug $mnt >/dev/null 2>&1
quotacheck -aug >/dev/null 2>&1
fi fi
# Building fs quota index # Adding quotacheck on reboot
quotacheck -um $mnt touch /forcequotacheck
# Adding weekly cron job # Adding cron job
echo "quotacheck -um $mnt" > /etc/cron.daily/quotacheck echo '#!/bin/bash' > /etc/cron.daily/quotacheck
echo 'touch /forcequotacheck' >> /etc/cron.daily/quotacheck
chmod a+x /etc/cron.daily/quotacheck chmod a+x /etc/cron.daily/quotacheck
# Enabling fs quota # Enabling group and user quota
if [ ! -z "$(quotaon -pa|grep " $mnt "|grep user|grep 'off')" ]; then if [ ! -z "$(quotaon -pa | grep " $mnt " | grep 'user\|group' | grep 'is off')" ]; then
quotaon $mnt 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 fi
# Updating DISK_QUOTA value # Updating vesta.conf value
if [ -z "$(grep DISK_QUOTA $VESTA/conf/vesta.conf)" ]; then if [ -z "$(grep DISK_QUOTA $VESTA/conf/vesta.conf)" ]; then
echo "DISK_QUOTA='yes'" >> $VESTA/conf/vesta.conf echo "DISK_QUOTA='yes'" >> $VESTA/conf/vesta.conf
else else