Skip to content

Commit ff5c772

Browse files
authored
Fix/v-add-sys-quota and v-delete-sys-quota (hestiacp#3991)
Add systemctl daemon-reload before mount and use v-change-sys-config-value to modify DISK_QUOTA value
1 parent f8d018e commit ff5c772

File tree

2 files changed

+19
-23
lines changed

2 files changed

+19
-23
lines changed

bin/v-add-sys-quota

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,7 @@ source_conf "$HESTIA/conf/hestia.conf"
2222
#----------------------------------------------------------#
2323

2424
# Ensure that quota kernel modules are installed
25-
kernel_module_check=$(find /lib/modules/$(uname -r) -type f -name '*quota_v*.ko*' | egrep '.*' && [ $? -eq 0 ])
26-
if [ -z "$kernel_module_check" ]; then
25+
if ! find "/lib/modules/$(uname -r)" -type f -name '*quota_v*.ko*' | grep -q '.*'; then
2726
# Install kernel modules for quota support.
2827
# Requires reboot to activate updated kernel.
2928
echo "Installing required kernel modules for quota support..."
@@ -33,8 +32,7 @@ if [ -z "$kernel_module_check" ]; then
3332
fi
3433

3534
# Checking quota package
36-
quota=$(which --skip-alias --skip-functions quota 2> /dev/null)
37-
if [ $? -ne 0 ]; then
35+
if ! type -P quota &>/dev/null; then
3836
if [ -f "/etc/redhat-release" ]; then
3937
dnf -y install quota > /dev/null 2>&1
4038
else
@@ -56,10 +54,11 @@ mnt=$(df -P /home | awk '{print $6}' | tail -n1)
5654
lnr=$(cat -n /etc/fstab | grep -v "#" | awk '{print $1,$3}' | grep "$mnt$" | cut -f 1 -d ' ')
5755
opt=$(sed -n ${lnr}p /etc/fstab | awk '{print $4}')
5856
fnd='usrquota\|grpquota\|usrjquota=aquota.user\|grpjquota=aquota.group\|jqfmt=vfsv0'
59-
if [ $(echo $opt | tr ',' '\n' | grep -x $fnd | wc -l) -ne 5 ]; then
57+
if [ "$(echo "$opt" | tr ',' '\n' | grep -c -x $fnd)" -ne 5 ]; then
6058
old=$(echo $(echo $opt | tr ',' '\n' | grep -v 'usrquota\|grpquota\|usrjquota=\|grpjquota=\|jqfmt=') | tr ' ' ',')
6159
new='usrquota,grpquota,usrjquota=aquota.user,grpjquota=aquota.group,jqfmt=vfsv0'
6260
sed -i "$lnr s/$opt/$old,$new/" /etc/fstab
61+
systemctl daemon-reload
6362
mount -o remount "$mnt"
6463
fi
6564

@@ -83,11 +82,7 @@ if [ -n "$(quotaon -pa | grep " $mnt " | grep 'user\|group' | grep 'is off')" ];
8382
fi
8483

8584
# Updating hestia.conf value
86-
if [ -z "$(grep DISK_QUOTA $HESTIA/conf/hestia.conf)" ]; then
87-
echo "DISK_QUOTA='yes'" >> $HESTIA/conf/hestia.conf
88-
else
89-
sed -i "s/DISK_QUOTA=.*/DISK_QUOTA='yes'/g" $HESTIA/conf/hestia.conf
90-
fi
85+
$BIN/v-change-sys-config-value "DISK_QUOTA" "yes"
9186

9287
# Rebuilding user quota
9388
for user in $("$BIN/v-list-users" list); do

bin/v-delete-sys-quota

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -31,37 +31,38 @@ check_hestia_demo_mode
3131

3232
# Deleting group and user quota on /home partition
3333
mnt=$(df -P /home | awk '{print $6}' | tail -n1)
34-
lnr=$(cat -n /etc/fstab | awk '{print $1,$3}' | grep "$mnt$" | cut -f 1 -d ' ')
34+
lnr=$(cat -n /etc/fstab | grep -v "#" | awk '{print $1,$3}' | grep "$mnt$" | cut -f 1 -d ' ')
3535
opt=$(sed -n ${lnr}p /etc/fstab | awk '{print $4}')
3636
fnd='usrquota\|grpquota\|usrjquota=\|grpjquota=\|jqfmt='
3737
if [ -n "$(echo $opt | grep $fnd)" ]; then
3838
rep=$(echo $(echo $opt | tr ',' '\n' | grep -v $fnd) | tr ' ' ',')
3939
sed -i "$lnr s/$opt/$rep/" /etc/fstab
40+
systemctl daemon-reload
4041
mount -o remount "$mnt"
4142
fi
4243

4344
# Disabling group and user quota
44-
quotaoff=$(which --skip-alias --skip-functions quotaoff 2> /dev/null)
45-
if [ $? -eq 0 ]; then
46-
if [ -n "$(quotaon -pa | grep " $mnt " | grep 'user\|group' | grep 'is on')" ]; then
47-
$quotaoff $mnt
45+
if quotaon="$(type -P quotaon 2>/dev/null)" && quotaoff="$(type -P quotaoff 2>/dev/null)"; then
46+
if "${quotaon}" -pa | grep " $mnt " | grep 'user\|group' | grep -q 'is on' &>/dev/null; then
47+
"$quotaoff" "$mnt"
4848
fi
4949
fi
5050

5151
# Deleting v1 + v2 group and user quota index
52-
for idx in $(echo 'quota.user quota.group aquota.user aquota.group'); do
52+
for idx in quota.user quota.group aquota.user aquota.group; do
5353
[ -e "$mnt/$idx" ] && rm -f "$mnt/$idx"
5454
done
5555

56-
# Deleting cron job
57-
rm -f /etc/cron.daily/quotacheck
56+
# Deleting cron job and forcequotacheck
57+
if [[ -f "/etc/cron.daily/quotacheck" ]]; then
58+
rm -f "/etc/cron.daily/quotacheck"
59+
fi
60+
if [[ -f "/forcequotacheck" ]]; then
61+
rm -f "/forcequotacheck"
62+
fi
5863

5964
# Updating hestia.conf value
60-
if [ -z "$(grep DISK_QUOTA $HESTIA/conf/hestia.conf)" ]; then
61-
echo "DISK_QUOTA='no'" >> $HESTIA/conf/hestia.conf
62-
else
63-
sed -i "s/DISK_QUOTA=.*/DISK_QUOTA='no'/g" $HESTIA/conf/hestia.conf
64-
fi
65+
$BIN/v-change-sys-config-value "DISK_QUOTA" "no"
6566

6667
#----------------------------------------------------------#
6768
# Hestia #

0 commit comments

Comments
 (0)