From 940eb07423c856cc2a40f0a5c0161f46c34e7136 Mon Sep 17 00:00:00 2001 From: Bin Qian Date: Tue, 2 Nov 2021 20:54:19 -0400 Subject: [PATCH] report open-ldap service is approaching or reaching FD limit openldap status to return 160 for open FD approaching limit (above 95%), return 161 for open FD reaches the limit. Depends-on: https://review.opendev.org/c/starlingx/ha/+/819130 Partial-Bug: 1952126 Change-Id: I27bc46709c74c592a8a6b9505f4f2edac742e1a9 Signed-off-by: Bin Qian --- openldap-config/files/initscript | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/openldap-config/files/initscript b/openldap-config/files/initscript index e572d74..599cf12 100755 --- a/openldap-config/files/initscript +++ b/openldap-config/files/initscript @@ -6,6 +6,12 @@ # . /etc/init.d/functions +PID_FILE='/var/run/slapd.pid' +MAX_FD_COUNT=4096 +ALARM_THRESHOLD=3891 # 95 % MAX +EXIT_APPROACH_LIMIT=160 +EXIT_LIMIT_REACHED=161 + ################################################################################ # Wait for a process to stop running. # @@ -27,6 +33,7 @@ function wait_for_proc_stop() return 1 } + slapd=/usr/sbin/slapd test -x "$slapd" || exit 0 @@ -36,7 +43,7 @@ case "$1" in start) echo -n "Starting SLAPD: " # Bump up the open file limit for created daemons - ulimit -n 4096 + ulimit -n $MAX_FD_COUNT if [ -f /etc/openldap/schema/cn=config.ldif ]; then start-stop-daemon --start --oknodo --quiet --exec $slapd \ -- -F /etc/openldap/schema/ @@ -81,7 +88,7 @@ case "$1" in wait_for_proc_stop $slapd 10 WRETVAL=$? done - rm -f /var/run/slapd.pid + rm -f '$PID_FILE' echo "." ;; status) @@ -89,6 +96,11 @@ case "$1" in [ $? -eq 0 ] || exit $? systemctl status nscd.service [ $? -eq 0 ] || exit $? + PID=`cat $PID_FILE` + FD_PATH="/proc/$PID/fd/" + FD_CNT=`ls $FD_PATH -l | wc -l` + [ "$FD_CNT" -lt "$MAX_FD_COUNT" ] || exit $EXIT_LIMIT_REACHED + [ "$FD_CNT" -lt "$ALARM_THRESHOLD" ] || exit $EXIT_APPROACH_LIMIT ;; restart) $0 stop