Difference between revisions of "Automatically setting quotaugidlimit"

From OpenVZ Virtuozzo Containers Wiki
Jump to: navigation, search
(+ploop)
 
(3 intermediate revisions by one other user not shown)
Line 1: Line 1:
If you are using second-level user/group quota for your containers, you have to take care that the value at every moment is high enough. Otherwise, newly created users and groups within the VE won't be able to own files.
+
If you are using second-level user/group quota with simfs for your containers, you have to take care that the value at every moment is high enough. Otherwise, newly created users and groups within the CT won't be able to own files. '''Note this is not required for ploop layout, in which quotaugidlimit is enabled with any non-zero value.'''
  
 
Rather than checking these values from time to time by hand, you can use the shell script from below to automatically set the quotaugidlimit based on the needs of the individual containers. Just setup a cronjob for it.
 
Rather than checking these values from time to time by hand, you can use the shell script from below to automatically set the quotaugidlimit based on the needs of the individual containers. Just setup a cronjob for it.
Line 17: Line 17:
 
for file in $FILES
 
for file in $FILES
 
do
 
do
 +
STRING=""
 +
VALUE=""
 +
INT=""
 +
CONFFILE=""
 +
VEID=""
 +
USERC=""
 +
GROUPC=""
 +
TOTAL=""
 +
 
# source the config file
 
# source the config file
 
. $file
 
. $file
Line 29: Line 38:
  
 
# check if quotaugidlimit is > 0
 
# check if quotaugidlimit is > 0
if [ $INT != 0 ];
+
if [ ! $INT == 0 ];
 
then
 
then
 
# get configfile name
 
# get configfile name
Line 40: Line 49:
 
TOTAL=$(($USERC + $GROUPC + 15))
 
TOTAL=$(($USERC + $GROUPC + 15))
  
# set the new quotaugidlimit for container
+
# only change if current value is lower
vzctl set $VEID --quotaugidlimit $TOTAL --save
+
if [ $TOTAL -gt $INT ];
 +
then
 +
# set the new quotaugidlimit for container
 +
vzctl set $VEID --quotaugidlimit $TOTAL --save
 +
echo "New quotaugidlimit set to $TOTAL for VEID $VEID\n"
 +
fi
 
fi
 
fi
 
fi
 
fi
Line 48: Line 62:
  
 
This will check for current users/groups count and increate the value by 15 - and set it as a new limit for the container.
 
This will check for current users/groups count and increate the value by 15 - and set it as a new limit for the container.
 +
 +
[[Category:HOWTO]]

Latest revision as of 14:26, 22 February 2013

If you are using second-level user/group quota with simfs for your containers, you have to take care that the value at every moment is high enough. Otherwise, newly created users and groups within the CT won't be able to own files. Note this is not required for ploop layout, in which quotaugidlimit is enabled with any non-zero value.

Rather than checking these values from time to time by hand, you can use the shell script from below to automatically set the quotaugidlimit based on the needs of the individual containers. Just setup a cronjob for it.

Script

#!/bin/bash

# If one of these files does not exist then something
# is really broken
[ -d /etc/vz/conf ] || exit 1

# get all configured VEs
FILES=/etc/vz/conf/*.conf

# loop through all VEs
for file in $FILES
do
	STRING=""
	VALUE=""
	INT=""
	CONFFILE=""
	VEID=""
	USERC=""
	GROUPC=""
	TOTAL=""

	# source the config file
	. $file

	# check if quotaugidlimit is set
	if grep -q "QUOTAUGIDLIMIT" $file
	then
		# get current quotaugidlimit
		STRING=`grep "QUOTAUGIDLIMIT" $file`
		VALUE=${STRING##*QUOTAUGIDLIMIT=\"}
		INT=${VALUE%?}

		# check if quotaugidlimit is > 0
		if [ ! $INT == 0 ];
		then
			# get configfile name
			CONFFILE=`basename $file`
			VEID=${CONFFILE%.*}

			# run commands "inside" the VE
			USERC=`cat $VE_PRIVATE$VEID/etc/passwd | wc -l`
			GROUPC=`cat $VE_PRIVATE$VEID/etc/group | wc -l`
			TOTAL=$(($USERC + $GROUPC + 15))

			# only change if current value is lower
			if [ $TOTAL -gt $INT ];
			then
				# set the new quotaugidlimit for container
				vzctl set $VEID --quotaugidlimit $TOTAL --save
				echo "New quotaugidlimit set to $TOTAL for VEID $VEID\n"
			fi
		fi
	fi
done

This will check for current users/groups count and increate the value by 15 - and set it as a new limit for the container.