From 5530e417428c7d5a3165db65ae4dc9f6086b3eb2 Mon Sep 17 00:00:00 2001 From: Maxim Biro Date: Thu, 18 Oct 2018 04:23:21 -0400 Subject: Increase NOFILE limit for tox-bootstrapd tox-bootstrapd can use around 600 TCP sockets during TCP server's normal functioning. Many systems default to having a soft limit of 1024 open file descriptors, which we are close to reaching, so it was suggested we bump that limit to a higher number. iphy suggested increasing it to 32768. --- other/bootstrap_daemon/tox-bootstrapd.sh | 35 ++++++++++++++++++++++++++++++-- 1 file changed, 33 insertions(+), 2 deletions(-) (limited to 'other/bootstrap_daemon/tox-bootstrapd.sh') diff --git a/other/bootstrap_daemon/tox-bootstrapd.sh b/other/bootstrap_daemon/tox-bootstrapd.sh index d33c38da..5f1e5c68 100644 --- a/other/bootstrap_daemon/tox-bootstrapd.sh +++ b/other/bootstrap_daemon/tox-bootstrapd.sh @@ -1,4 +1,4 @@ -#! /bin/sh +#! /bin/bash ### BEGIN INIT INFO # Provides: tox-bootstrapd # Required-Start: $remote_fs $syslog @@ -22,6 +22,35 @@ SCRIPTNAME=/etc/init.d/$NAME USER=tox-bootstrapd GROUP=tox-bootstrapd +# Set ulimit -n based on number of fds available. +# This check is borrowed from Debian's tor package, with a few modifications. +if [ -r /proc/sys/fs/file-max ]; then + system_max=$(cat /proc/sys/fs/file-max) + if [ "$system_max" -gt "80000" ] ; then + MAX_FILEDESCRIPTORS=32768 + elif [ "$system_max" -gt "40000" ] ; then + MAX_FILEDESCRIPTORS=16384 + elif [ "$system_max" -gt "20000" ] ; then + MAX_FILEDESCRIPTORS=8192 + elif [ "$system_max" -gt "10000" ] ; then + MAX_FILEDESCRIPTORS=4096 + else + MAX_FILEDESCRIPTORS=1024 + cat << EOF + +Warning: Your system has very few file descriptors available in total. + +Maybe you should try raising that by adding 'fs.file-max=100000' to your +/etc/sysctl.conf file. Feel free to pick any number that you deem appropriate. +Then run 'sysctl -p'. See /proc/sys/fs/file-max for the current value, and +file-nr in the same directory for how many of those are used at the moment. + +EOF + fi +else + MAX_FILEDESCRIPTORS=32768 +fi + # Exit if the package is not installed [ -x "$DAEMON" ] || exit 0 @@ -48,6 +77,8 @@ do_start() fi chown $USER:$GROUP $PIDDIR start-stop-daemon --start --quiet --pidfile $PIDFILE --exec $DAEMON --test --chuid $USER > /dev/null || return 1 + # TCP Server needs to be able to have lots of TCP sockets open. + ulimit -n $MAX_FILEDESCRIPTORS start-stop-daemon --start --quiet --pidfile $PIDFILE --exec $DAEMON --chuid $USER -- $DAEMON_ARGS || return 2 } @@ -113,4 +144,4 @@ case "$1" in exit 3 ;; esac -exit 0 \ No newline at end of file +exit 0 -- cgit v1.2.3