#!/bin/bash # Source an auxiliary options file if we have one, and pick up OPTIONS, # SLAPD_OPTIONS, and SLURPD_OPTIONS. if [ -r /etc/sysconfig/ldap ] ; then . /etc/sysconfig/ldap fi LDAPUSER="${LDAPUSER:-ldap}" LDAPGROUP="${LDAPGROUP:-ldap}" SLAPDCONF="${SLAPDCONF:-/etc/openldap/slapd.conf}" QUIET=0 bdbdirs=(`awk \ 'BEGIN {OFS=":"} /[:space:]*^database[:space:]*\w*/ {db=$2} /^[:space:]*directory[:space:]*\w*/ {if (db=="bdb") print $2}' \ $SLAPDCONF|sed -e 's/[" ]//g'`) if [ -x /usr/bin/slapd_db_stat ] then # private db_stat is the best choice DBSTAT=/usr/bin/slapd_db_stat elif [ -x /usr/bin/db_stat ] then DBSTAT=/usr/bin/db_stat else DBSTAT="" echo "Warning: no db_stat available" fi while getopts q option do case "$option" in q) QUIET=1;; esac done function tune () { REPORT="$1" [ -n "$DBSTAT" ] || return 4 local MEMREQ for dbdir in ${bdbdirs[*]} do [ "$QUIET" -eq 1 ] || echo "Checking cache size for ${dbdir}" MEMREQ=0 for dbfile in ${dbdir}/*.bdb #id2entry.bdb dn2id.bdb do MEMREQ=$[MEMREQ+`$DBSTAT -h ${dbdir} -d ${dbfile}|awk '/Number of tree internal pages/ {pages=$1}; /Underlying database page size/ {page_size=$1}; END {print (pages+1)*page_size}'`] done [ -e ${dbdir}/DB_CONFIG ] && MEMUSED=`awk '/^set_cachesize/ {print (($2*1024^3)+$3)}' ${dbdir}/DB_CONFIG` MEMUSED="${MEMUSED:-262144}" if [ $MEMUSED -lt $MEMREQ ] then MEMREQGB="$[MEMREQ/1024/1024/1024]" MEMREQKB="$[MEMREQ%(1024*1024*1024)]" [ "$QUIET" -eq 1 ] || echo "\tCache memory ($MEMUSED bytes) less than minimum cache memory required ($MEMREQ bytes)" [ "$QUIET" -eq 1 ] || echo "You should add \"set_cachesize $MEMREQGB $MEMREQKB 0\" to ${dbdir}/DB_CONFIG" [ "$QUIET" -eq 1 ] || echo "and stop and start the service" [ "$QUIET" -eq 0 ] || echo "$dbdir set_cachesize $MEMREQGB $MEMREQKB 0" else if [ "$REPORT" == "full" ] then if [ "$QUIET" -eq 0 ] then echo -e "\tCache ($MEMUSED bytes) > minimum required cache ($MEMREQ bytes)" else echo "$dbdir ok" fi fi fi if [ "$REPORT" == "full" -a "$QUIET" -eq 0 ] then #show percentages too #gprintf "Cache memory set to: %s kB, minimum required cache memory: %s kB\n" "$MEMUSED" "$MEMREQ" PERC=`$DBSTAT -h ${dbdir} -m|awk '/Requested pages found in the cache/ {incache=$1 + incache}; /Requested pages not found in the cache/ {notincache=$1 + notincache}; END {print (incache * 100)/(notincache + incache)}'` echo -e "\tAverage pages found in cache for this database: $PERC %" if [ "${PERC%%\.*}" -lt 95 ] then echo -e"\tThis database is under-performing, you may need a bigger cache" echo "Please run '$DBSTAT -m -h ${dbdir}' for more statistics" fi fi done } tune full