Skip to content

Commit bb037fa

Browse files
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
1 parent 8503efa commit bb037fa

File tree

1 file changed

+27
-20
lines changed

1 file changed

+27
-20
lines changed

bin/v-add-sys-quota

Lines changed: 27 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
#!/bin/bash
22
# info: add system quota
3-
# opions: NONE
3+
# options: NONE
44
#
55
# The script enables filesystem quota on /home patition
66

77

88
#----------------------------------------------------------#
9-
# Variable&Function #
9+
# Variable & Function #
1010
#----------------------------------------------------------#
1111

1212
# Includes
@@ -19,7 +19,8 @@ source $VESTA/conf/vesta.conf
1919
#----------------------------------------------------------#
2020

2121
# Checking quota package
22-
if [ ! -e "/usr/sbin/setquota" ]; then
22+
quota=$(which --skip-alias --skip-functions quota 2>/dev/null)
23+
if [ $? -ne 0 ]; then
2324
if [ -e "/etc/redhat-release" ]; then
2425
yum -y install quota >/dev/null 2>&1
2526
check_result $? "quota package installation failed" $E_UPDATE
@@ -35,34 +36,40 @@ fi
3536
# Action #
3637
#----------------------------------------------------------#
3738

38-
# Adding usrquota option on /home partition
39-
mnt=$(df -P /home |awk '{print $6}' |tail -n1)
40-
lnr=$(cat -n /etc/fstab |awk '{print $1,$3}' |grep "$mnt$" |cut -f 1 -d ' ')
41-
options=$(sed -n ${lnr}p /etc/fstab |awk '{print $4}')
42-
if [ -z "$(echo $options |grep usrquota)" ]; then
43-
sed -i "$lnr s/$options/$options,usrquota/" /etc/fstab
39+
# Adding group and user quota on /home partition
40+
mnt=$(df -P /home | awk '{print $6}' | tail -n1)
41+
lnr=$(cat -n /etc/fstab | awk '{print $1,$3}' | grep "$mnt$" | cut -f 1 -d ' ')
42+
opt=$(sed -n ${lnr}p /etc/fstab | awk '{print $4}')
43+
fnd='usrquota\|grpquota\|usrjquota=aquota.user\|grpjquota=aquota.group\|jqfmt=vfsv0'
44+
if [ $(echo $opt | tr ',' '\n' | grep -x $fnd | wc -l) -ne 5 ]; then
45+
old=$(echo $(echo $opt | tr ',' '\n' | grep -v 'usrquota\|grpquota\|usrjquota=\|grpjquota=\|jqfmt=') | tr ' ' ',')
46+
new='usrquota,grpquota,usrjquota=aquota.user,grpjquota=aquota.group,jqfmt=vfsv0'
47+
sed -i "$lnr s/$opt/$old,$new/" /etc/fstab
4448
mount -o remount $mnt
4549
fi
4650

47-
# Adding aquota.user file
48-
if [ ! -e "$mnt/aquota.user" ]; then
49-
quotacheck -cu $mnt >/dev/null 2>&1
51+
# Adding v2 group and user quota index
52+
if [ ! -e "$mnt/aquota.user" ] || [ ! -e "$mnt/aquota.group" ]; then
53+
quotaoff $mnt
54+
quotacheck -cug $mnt >/dev/null 2>&1
55+
quotacheck -aug >/dev/null 2>&1
5056
fi
5157

52-
# Building fs quota index
53-
quotacheck -um $mnt
58+
# Adding quotacheck on reboot
59+
touch /forcequotacheck
5460

55-
# Adding weekly cron job
56-
echo "quotacheck -um $mnt" > /etc/cron.daily/quotacheck
61+
# Adding cron job
62+
echo '#!/bin/bash' > /etc/cron.daily/quotacheck
63+
echo 'touch /forcequotacheck' >> /etc/cron.daily/quotacheck
5764
chmod a+x /etc/cron.daily/quotacheck
5865

59-
# Enabling fs quota
60-
if [ ! -z "$(quotaon -pa|grep " $mnt "|grep user|grep 'off')" ]; then
66+
# Enabling group and user quota
67+
if [ ! -z "$(quotaon -pa | grep " $mnt " | grep 'user\|group' | grep 'is off')" ]; then
6168
quotaon $mnt
62-
check_result $? "quota can't be enabled in $mtn" $E_DISK
69+
check_result $? "quota can't be enabled in $mnt" $E_DISK
6370
fi
6471

65-
# Updating DISK_QUOTA value
72+
# Updating vesta.conf value
6673
if [ -z "$(grep DISK_QUOTA $VESTA/conf/vesta.conf)" ]; then
6774
echo "DISK_QUOTA='yes'" >> $VESTA/conf/vesta.conf
6875
else

0 commit comments

Comments
 (0)