Skip to content

Commit 9087a5b

Browse files
committed
File system quota support
1 parent 391c6ca commit 9087a5b

File tree

5 files changed

+214
-7
lines changed

5 files changed

+214
-7
lines changed

bin/v-add-sys-quota

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
#!/bin/bash
2+
# info: add system quota
3+
# opions: NONE
4+
#
5+
# The script enables filesystem quota on /home patition
6+
7+
8+
#----------------------------------------------------------#
9+
# Variable&Function #
10+
#----------------------------------------------------------#
11+
12+
# Includes
13+
source $VESTA/func/main.sh
14+
source $VESTA/conf/vesta.conf
15+
16+
17+
#----------------------------------------------------------#
18+
# Verifications #
19+
#----------------------------------------------------------#
20+
21+
# Checking quota package
22+
if [ ! -e "/usr/sbin/setquota" ]; then
23+
if [ -e "/etc/redhat-release" ]; then
24+
yum -y install quota >/dev/null 2>&1
25+
result=$?
26+
else
27+
export DEBIAN_FRONTEND=noninteractive
28+
apt-get -y install quota >/dev/null 2>&1
29+
result=$?
30+
fi
31+
32+
# Checking installation status
33+
if [ "$result" -ne 0 ]; then
34+
echo "Error: quota package wasn't successfully installed"
35+
log_event "$E_UPDATE" "$EVENT"
36+
exit $E_UPDATE
37+
fi
38+
fi
39+
40+
41+
#----------------------------------------------------------#
42+
# Action #
43+
#----------------------------------------------------------#
44+
45+
# Adding usrquota option on /home partition
46+
mnt=$(df -P /home |awk '{print $6}' |tail -n1)
47+
lnr=$(cat -n /etc/fstab |awk '{print $1,$3}' |grep "$mnt$" |cut -f 1 -d ' ')
48+
options=$(sed -n ${lnr}p /etc/fstab |awk '{print $4}')
49+
if [ -z "$(echo $options |grep usrquota)" ]; then
50+
sed -i "$lnr s/$options/$options,usrquota/" /etc/fstab
51+
mount -o remount $mnt
52+
fi
53+
54+
# Adding aquota.user file
55+
if [ ! -e "$mnt/aquota.user" ]; then
56+
quotacheck -cu $mnt >/dev/null 2>&1
57+
fi
58+
59+
# Building fs quota index
60+
quotacheck -um $mnt
61+
62+
# Adding weekly cron job
63+
echo "quotacheck -um $mnt" > /etc/cron.daily/quotacheck
64+
chmod a+x /etc/cron.daily/quotacheck
65+
66+
# Enabling fs quota
67+
if [ ! -z "$(quotaon -pa|grep " $mnt "|grep user|grep 'off')" ]; then
68+
quotaon $mnt
69+
fi
70+
71+
# Updating DISK_QUOTA value
72+
if [ -z "$(grep DISK_QUOTA $VESTA/conf/vesta.conf)" ]; then
73+
echo "DISK_QUOTA='yes'" >> $VESTA/conf/vesta.conf
74+
else
75+
sed -i "s/DISK_QUOTA=.*/DISK_QUOTA='yes'/g" $VESTA/conf/vesta.conf
76+
fi
77+
78+
# Rebuilding user quota
79+
for user in $(ls $VESTA/data/users); do
80+
$BIN/v-update-user-quota $user
81+
done
82+
83+
84+
#----------------------------------------------------------#
85+
# Vesta #
86+
#----------------------------------------------------------#
87+
88+
# Logging
89+
log_event "$OK" "$EVENT"
90+
91+
exit

bin/v-add-user

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -97,17 +97,10 @@ if [ ! -z "$DNS_SYSTEM" ]; then
9797
chmod 751 $HOMEDIR/$user/conf/dns
9898
fi
9999

100-
101100
# Set permissions
102101
chmod a+x $HOMEDIR/$user
103102
chattr +i $HOMEDIR/$user/conf
104103

105-
# Checking quota
106-
if [ ! -z "$DISK_QUOTA" ]; then
107-
DISK_QUOTA=$(echo "$pkg_data" | grep 'DISK_QUOTA' | cut -f 2 -d \')
108-
#$BIN/v-add-user_quota "$user" "$DISK_QUOTA"
109-
fi
110-
111104

112105
#----------------------------------------------------------#
113106
# Vesta #
@@ -212,6 +205,12 @@ TIME='$TIME'
212205
DATE='$DATE'" > $USER_DATA/user.conf
213206
chmod 660 $USER_DATA/user.conf
214207

208+
# Updating quota
209+
if [ "$DISK_QUOTA" = 'yes' ]; then
210+
echo "Setting quota"
211+
$BIN/v-update-user-quota "$user"
212+
fi
213+
215214
# Updating admin counter
216215
if [ "$user" != 'admin' ]; then
217216
increase_user_value 'admin' '$U_USERS'

bin/v-delete-sys-quota

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
#!/bin/bash
2+
# info: delete system quota
3+
# opions: NONE
4+
#
5+
# The script disables filesystem quota on /home patition
6+
7+
8+
#----------------------------------------------------------#
9+
# Variable&Function #
10+
#----------------------------------------------------------#
11+
12+
# Includes
13+
source $VESTA/func/main.sh
14+
source $VESTA/conf/vesta.conf
15+
16+
17+
#----------------------------------------------------------#
18+
# Verifications #
19+
#----------------------------------------------------------#
20+
21+
22+
#----------------------------------------------------------#
23+
# Action #
24+
#----------------------------------------------------------#
25+
26+
# Deleting usrquota on /home partition
27+
mnt=$(df -P /home |awk '{print $6}' |tail -n1)
28+
lnr=$(cat -n /etc/fstab |awk '{print $1,$3}' |grep "$mnt$" |cut -f 1 -d ' ')
29+
options=$(sed -n ${lnr}p /etc/fstab |awk '{print $4}')
30+
if [ ! -z "$(echo $options |grep usrquota)" ]; then
31+
sed -i "$lnr s/,usrquota//" /etc/fstab
32+
mount -o remount $mnt
33+
fi
34+
35+
# Disabling fs quota
36+
if [ -z "$(quotaon -pa|grep " $mnt "|grep user|grep 'off')" ]; then
37+
quotaoff $mnt
38+
fi
39+
40+
# Deleting quota index
41+
if [ -e "$mnt/aquota.user" ]; then
42+
rm $mnt/aquota.user
43+
fi
44+
45+
# Deleting weekly cron job
46+
rm -f /etc/cron.daily/quotacheck
47+
48+
# Updating DISK_QUOTA value
49+
if [ -z "$(grep DISK_QUOTA $VESTA/conf/vesta.conf)" ]; then
50+
echo "DISK_QUOTA='no'" >> $VESTA/conf/vesta.conf
51+
else
52+
sed -i "s/DISK_QUOTA=.*/DISK_QUOTA='no'/g" $VESTA/conf/vesta.conf
53+
fi
54+
55+
56+
#----------------------------------------------------------#
57+
# Vesta #
58+
#----------------------------------------------------------#
59+
60+
# Logging
61+
log_event "$OK" "$EVENT"
62+
63+
exit

bin/v-rebuild-user

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,11 @@ is_object_unsuspended 'user' 'USER' "$user"
3636
# Action #
3737
#----------------------------------------------------------#
3838

39+
# Update disk quota
40+
if [ "$DISK_QUOTA" = 'yes' ]; then
41+
$BIN/v-update-user-quota $user
42+
fi
43+
3944
# Rebuild user
4045
rebuild_user_conf
4146

bin/v-update-user-quota

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
#!/bin/bash
2+
# info: update user disk quota
3+
# options: USER
4+
#
5+
# The functions upates disk quota for specific user
6+
7+
8+
#----------------------------------------------------------#
9+
# Variable&Function #
10+
#----------------------------------------------------------#
11+
12+
# Argument defenition
13+
user=$1
14+
15+
# Includes
16+
source $VESTA/func/main.sh
17+
source $VESTA/conf/vesta.conf
18+
19+
20+
#----------------------------------------------------------#
21+
# Verifications #
22+
#----------------------------------------------------------#
23+
24+
check_args '1' "$#" 'USER'
25+
validate_format 'user'
26+
is_object_valid 'user' 'USER' "$user"
27+
28+
29+
#----------------------------------------------------------#
30+
# Action #
31+
#----------------------------------------------------------#
32+
33+
# Updating disk quota
34+
soft=$(get_user_value '$DISK_QUOTA')
35+
soft=$((soft * 100))
36+
hard=$((soft + 50000))
37+
38+
mnt=$(df -P /home |awk '{print $6}' |tail -n1)
39+
setquota $user $soft $hard 0 0 $mnt
40+
41+
42+
#----------------------------------------------------------#
43+
# Vesta #
44+
#----------------------------------------------------------#
45+
46+
# Logging
47+
log_event "$OK" "$EVENT"
48+
49+
exit

0 commit comments

Comments
 (0)