#!/bin/sh ### BEGIN INIT INFO # Provides: quota # Short-Description: Enable user quota # Required-Start: $remote_fs # Required-Stop: $remote_fs # Default-Start: S # Default-Stop: 0 6 ### END INIT INFO PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin DESC="quota service" # names of binaries check=/sbin/quotacheck on=/sbin/quotaon off=/sbin/quotaoff quotaisoff=/var/lib/quota/off quotaisnew=/var/lib/quota/new ALLFLAGS=-aug CHECKFLAGS=${ALLFLAGS}m USERFLAGS=-uc GROUPFLAGS=-gc . /lib/lsb/init-functions # create list of all fs with quota scan_fstab() { tmplist=`grep "^[ ]*[^#].*$1" /etc/fstab | \ sed -e 's/\(^[[:space:]]*[^[:space:]]*[[:space:]]*[^[:space:]]*[[:space:]]*[^[:space:]]*\).*/\1/g' \ -e 's/^[[:space:]]*[^[:space:]]*[[:space:]]*//g'` list=${tmplist:=empty} } set -e case "$1" in start) # Check if quota already has been enabled LC_MESSAGES=C $on -ap|grep -q "is off" || exit 0 # Check all filesystems if quota is new or wasn't shut down correctly log_action_begin_msg 'Checking quotas'; if [ -x $check ] && ( [ ! -f $quotaisoff ] || [ -f $quotaisnew ] ); then $check $CHECKFLAGS || $check -c $CHECKFLAGS log_action_end_msg 0 else # if some filesystems are new check just these filesystems scan_fstab "usrquota" set -- $list while [ $# -ge 2 ] do if [ "$2" != "xfs" ] then if test ! -e $1/quota.user && test ! -e $1/aquota.user; then log_warning_msg "Warning: user quota not configured in filesystem \`$1.'" elif test ! -e $1/aquota.user; then test ! -s $1/quota.user && $check $USERFLAGS $1 elif test ! -s $1/aquota.user; then $check $USERFLAGS $1 fi fi shift; shift done scan_fstab "grpquota" set $list while [ $# -ge 2 ] do if [ "$2" != "xfs" ] then if test ! -e $1/quota.group && test ! -e $1/aquota.group; then log_warning_msg "Warning: group quota not configured in filesystem \`$1.'" elif test ! -e $1/aquota.group; then test ! -s $1/quota.group && $check $GROUPFLAGS $1 elif test ! -s $1/aquota.group; then $check $GROUPFLAGS $1 fi fi shift; shift done log_action_end_msg 0 fi # Remove quota-off and quota-new files rm -f $quotaisoff $quotaisnew # Turn quotas on. if [ -x $on ] then log_action_begin_msg 'Turning on quotas'; $on $ALLFLAGS log_action_end_msg 0 fi ;; stop) if [ -x $off ] then log_action_begin_msg 'Turning off quotas' $off $ALLFLAGS || true # Create quota-on file touch $quotaisoff log_action_end_msg 0 fi ;; restart|force-reload) # # If the "reload" option is implemented, move the "force-reload" # option to the "reload" entry above. If not, "force-reload" is # just the same as "restart". # $0 stop $0 start ;; status) if LC_MESSAGES=C $on -ap | grep -q "is off"; then log_failure_msg "quota is off" exit 3 else log_success_msg "quota is on" exit 0 fi ;; *) echo "Usage: $0 {start|stop|restart|force-reload|status}" >&2 exit 1 ;; esac exit 0