From 644452a62fde5fec66dab56c4f47204f42b57bac Mon Sep 17 00:00:00 2001
From: Peter Palfrader <peter@palfrader.org>
Date: Wed, 20 Feb 2008 22:28:09 +0000
Subject: Change the default for MAX_FILEDESCRIPTORS in our init script to
 depend on the number of system-wide available file descriptors:
 /proc/sys/fs/file-max is bigger than 100k, set ulimit -n to 32k, if it's
 smaller than 20k set it to 1024.  Big servers at the moment regularly use
 more than 10k FDs, so our old default of 8k no longer is sufficient.  On the
 other hand we don't want lower end systems to run out of FDs on Tor's
 account.

svn:r13625
---
 debian/changelog   | 12 ++++++++++++
 debian/tor.default |  9 +++++++--
 debian/tor.init    | 15 ++++++++++++++-
 3 files changed, 33 insertions(+), 3 deletions(-)

diff --git a/debian/changelog b/debian/changelog
index d210a897c..397e87392 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -1,3 +1,15 @@
+tor (0.2.0.19-alpha+svn-1) unreleased; urgency=low
+
+  * Change the default for MAX_FILEDESCRIPTORS in our init script to depend
+    on the number of system-wide available file descriptors:
+    /proc/sys/fs/file-max is bigger than 100k, set ulimit -n to 32k, if it's
+    smaller than 20k set it to 1024.  Big servers at the moment regularly use
+    more than 10k FDs, so our old default of 8k no longer is sufficient.  On
+    the other hand we don't want lower end systems to run out of FDs on Tor's
+    account.
+
+ -- Peter Palfrader <weasel@debian.org>  Wed, 20 Feb 2008 23:27:35 +0100
+
 tor (0.2.0.19-alpha-1) experimental; urgency=low
 
   * New upstream version.
diff --git a/debian/tor.default b/debian/tor.default
index 237e5bc52..1ae1e1586 100644
--- a/debian/tor.default
+++ b/debian/tor.default
@@ -9,10 +9,15 @@ RUN_DAEMON="yes"
 
 #
 # Servers sometimes may need more than the default 1024 file descriptors
-# if they are very busy and have many clients connected to them.
+# if they are very busy and have many clients connected to them.  The top
+# servers as of early 2008 regularly have more than 10000 connected
+# clients.
 #  (ulimit -n)
 #
-MAX_FILEDESCRIPTORS=8192
+# (the default varies as it depends on the number of available system-wide file
+#  descriptors.  See the init script in /etc/init.d/tor for details.)
+#
+# MAX_FILEDESCRIPTORS=
 
 #
 # If tor is seriously hogging your CPU, taking away too much cycles from
diff --git a/debian/tor.init b/debian/tor.init
index ec5707d7d..415467e87 100644
--- a/debian/tor.init
+++ b/debian/tor.init
@@ -25,7 +25,20 @@ TORPID=$TORPIDDIR/tor.pid
 DEFAULTSFILE=/etc/default/$NAME
 WAITFORDAEMON=60
 ARGS=""
-MAX_FILEDESCRIPTORS=8192
+# Let's try to figure our some sane defaults:
+if [ -r /proc/sys/fs/file-max ]; then
+	system_max=`cat /proc/sys/fs/file-max`
+	if [ "$system_max" -gt "100000" ] ; then
+		MAX_FILEDESCRIPTORS=32768
+	elif [ "$system_max" -gt "20000" ] ; then
+		MAX_FILEDESCRIPTORS=8192
+	else
+		MAX_FILEDESCRIPTORS=1024
+	fi
+else
+	MAX_FILEDESCRIPTORS=8192
+fi
+
 NICE=""
 
 test -x $DAEMON || exit 0
-- 
cgit v1.2.3