Jim Somerville 29b55438df Increase soft limit on slapd open files to 4096
Problem:

After installing/configuring/managing 206 subclouds,
"Can't contact LDAP server" errors were reported when
running sudo commands, and it took a long time to get
to a password prompt when running sudo.

Noted lots of 'Too many open files' logs in local4.log for
the slapd process.

Fix:

We increase the soft limit on the number of open
files for ldap up to the current hard limit of 4096,
from the previous soft limit of 1024.

We do this by running ulimit in the init script for
ldap.  The right way to do this would've been to add
the following systemd config file to the system:
/etc/systemd/system/slapd.service.d/limits.conf
with content:

[Service]
LimitNOFILE=4096

But it doesn't work.  It looks like launching the daemon
from systemd via init scripts interferes with the systemd
ulimit mechanism in some way.

Also openldap source has been checked to see if it can handle
4096 open files, and yes, the FD_SETSIZE is at 4096
already.  Going beyond 4096 will require a change to the
hard limit and source code change to openldap to get a
larger FD_SETSIZE defined.

Change-Id: I0c2da8e7a149a5ea41d8fbde5ecfb3ffac7765e0
Closes-Bug: 1888874
Signed-off-by: Jim Somerville <Jim.Somerville@windriver.com>
2020-07-27 10:51:09 -04:00

103 lines
2.3 KiB
Bash
Executable File

#! /bin/sh
#
# This is an init script for openembedded
# Copy it to /etc/init.d/openldap and type
# > update-rc.d openldap defaults 60
#
. /etc/init.d/functions
################################################################################
# Wait for a process to stop running.
#
################################################################################
function wait_for_proc_stop()
{
PROGNAME=$1
TIMEOUT=${2:-"5"}
for I in $(seq 1 $TIMEOUT); do
PID=$(pidof $PROGNAME 2> /dev/null)
if [ $? -ne 0 ]; then
## already dead
return 0
fi
sleep 1
done
return 1
}
slapd=/usr/sbin/slapd
test -x "$slapd" || exit 0
RETVAL=0
case "$1" in
start)
echo -n "Starting SLAPD: "
# Bump up the open file limit for created daemons
ulimit -n 4096
if [ -f /etc/openldap/schema/cn=config.ldif ]; then
start-stop-daemon --start --oknodo --quiet --exec $slapd \
-- -F /etc/openldap/schema/
RETVAL=$?
else
start-stop-daemon --start --oknodo --quiet --exec $slapd
RETVAL=$?
fi
if [ $RETVAL -ne 0 ]; then
echo "Failed to start SLAPD."
exit $RETVAL
fi
# we need to start nscd service as part of this openldap
# init.d script since SM manages this as a service and both
# daemons should be running on a controller host
systemctl status nscd.service
if [ $? -ne 0 ]; then
echo -n "Starting NSCD: "
systemctl start nscd.service
RETVAL=$?
if [ $RETVAL -ne 0 ]; then
echo "Failed to start NSCD."
exit $RETVAL
fi
fi
echo "."
;;
stop)
echo -n "Stopping NSCD: "
systemctl stop nscd.service
rm -f /var/run/nscd/nscd.pid
echo -n "Stopping SLAPD: "
start-stop-daemon --retry 60 --stop --oknodo --quiet --pidfile /var/run/slapd.pid
RETVAL=$?
wait_for_proc_stop $slapd 10
WRETVAL=$?
while [ $WRETVAL -eq 1 ]; do
killproc $slapd
wait_for_proc_stop $slapd 10
WRETVAL=$?
done
rm -f /var/run/slapd.pid
echo "."
;;
status)
status $slapd
[ $? -eq 0 ] || exit $?
systemctl status nscd.service
[ $? -eq 0 ] || exit $?
;;
restart)
$0 stop
$0 start
;;
*)
echo "Usage: /etc/init.d/openldap {start|stop|status|restart}"
exit 1
esac
exit $RETVAL