Heartbeatでquotaを使う

Heartbeatで動的にマウントしたファイルシステムでquotaを使うには、ちょっとした工夫が必要です。

1. /etc/ha.d/resource.d/Quota を作成します。
私はネットから拾ってきたものをそのまま使いました。

2. /etc/ha.d/resource.d/Quotaに実行権限を付与します。

# chmod +x /etc/ha.d/resource.d/Quota

3. /var/lib/heartbeat/crm/cib.xml の~の中に設定を追加します。
クラスタが動作中の場合、/tmp/cib.xmlに編集済みのファイルを置いて"cibadmin -U -x /tmp/cib.xml"で更新した方が楽です。
※パラメータ(name="1"~"4")は適宜変えてください。

<primitive class="heartbeat" id="Quota" provider="heartbeat" type="Quota">
<instance_attributes id="Quota_inst_attr">
<attributes>
<nvpair id="Quota_attr_1" name="1" value="y"/>
<nvpair id="Quota_attr_2" name="2" value="y"/>
<nvpair id="Quota_attr_3" name="3" value="y"/>
<nvpair id="Quota_attr_4" name="4" value="/work"/>
</attributes>
</instance_attributes>
</primitive>

テスト環境では問題なく動いています。
実環境で使う場合には自己責任でお願いします。


/etc/ha.d/resource.d/Quota

#!/bin/sh
#
# Quota
#      Description: Manages the quota(s) on a shared storage medium.
#  Original Author: Marc Schmitt (mschmitt@xxxxxxxxxxx)
# Original Release: 18 April 2003
#          Support: linux-ha@xxxxxx
#         Based on: Linux-HA Filesystem resource script
#
# usage: ./Quota     {start|stop|status}
#
# : use user quota
#: use group quota
#: run quota check
# : the mount point of the filesystem
#
#
# An example usage in /etc/ha.d/haresources:
#    node1  10.0.0.170 Filesystem::/dev/sda1::/data1::ext3::usrquota Quota::y::n::n::/data1
#
unset LC_ALL; export LC_ALL
unset LANGUAGE; export LANGUAGE
prefix=/usr
exec_prefix=/usr
#. /etc/ha.d/shellfuncs
. /etc/ha.d/shellfuncs
# Utilities used by this script
QUOTAON=/sbin/quotaon
QUOTAOFF=/sbin/quotaoff
QUOTACHECK=/sbin/quotacheck
MOUNT=/bin/mount
check_util () {
if [ ! -x "$1" ] ; then
ha_log "ERROR: setup problem: Couldn't find utility $1"
exit 1
fi
}
usage() {
cat <    {start|stop|status}
 : use user quota
: use group quota
: run quota check
 : the mount point of the filesystem
EOT
}
if [ $# -ne 5 ] ; then
usage
exit 1
fi
# Check the arguments passed to this script
DOUSERQUOTA=$1
DOGROUPQUOTA=$2
DOQUOTACHECK=$3
MOUNTPOINT=$4
operation=$5
options="-"
if [ ! -d "$MOUNTPOINT" ] ; then
ha_log "ERROR: Couldn't find directory $MOUNTPOINT to manage quotas on"
usage
exit 1
fi
[ "$DOUSERQUOTA" = "y" ] && options="${options}u"
[ "$DOGROUPQUOTA" = "y" ] && options="${options}g"
if [ "$options" = "-" ] ; then
ha_log "ERROR: Bad arguments"
usage
exit 1
fi
# Check to make sure the utilites are found
check_util $QUOTAON
check_util $QUOTAOFF
check_util $QUOTACHECK
# Look for the 'start', 'stop' or status argument
case "$operation" in
#
# START: Turn on quota(s)
#
start)
# See if the device is already mounted.
$MOUNT | cut -d' ' -f3 | grep -e "^$MOUNTPOINT$" >/dev/null
if [ $? -eq 1 ] ; then
ha_log "ERROR: Filesystem $MOUNTPOINT is not mounted!"
exit 1
fi
if
[ "$DOQUOTACHECK" = "y" ]
then
ha_log "info: Starting quota check on $MOUNTPOINT"
$QUOTACHECK $options $MOUNTPOINT
# NOTE: if any errors at all are detected, it returns non-zero
if
[ $? -ge 1 ]
then
ha_log "ERROR: Couldn't sucessfully check the quota for $MOUNTPOINT"
exit 1
fi
fi
# Turn on quota(s) on the filesystem.
if
$QUOTAON $options $MOUNTPOINT
then
: # Turning on quota(s) worked!
else
ha_log "ERROR: Couldn't turn on quota(s) on $MOUNTPOINT"
exit 1
fi
# end of start)
;;
#
# STOP: Turn off quota(s)
#
stop)
# See if the filesystem is currently mounted
if
$MOUNT | grep -e " on $MOUNTPOINT " >/dev/null
then
# Turn quota(s) off
$QUOTAOFF $options $MOUNTPOINT
if [ $? -ne 0 ] ; then
ha_log "ERROR: Couldn't turn off quota(s) on $MOUNTPOINT"
exit 1
fi
else
ha_log "WARNING: Filesystem $MOUNTPOINT not mounted?"
fi
# end of stop)
;;
#
# STATUS: are quota(s) turned on or not?
#
status)
$QUOTAON -p $options $MOUNTPOINT
# end of status)
;;
*)
echo "This script should be run with a fifth argument of 'start', 'stop', or 'status'"
usage
exit 1
;;
esac
# If you got to this point, chances are everything is O.K.
exit 0;