Apple Event: May 7th at 7 am PT

Looks like no one’s replied in a while. To start the conversation again, simply ask a new question.

420 Too Many Open Files

I'm running Apache 2.2 under OS X Server 10.5.2. In the wake of Security Update 2008-002, Apache refuses to run, with the following log entries:

[Wed Mar 19 17:01:16 2008] [notice] Graceful restart requested, doing restart
[Wed Mar 19 17:01:16 2008] [error] (9)Bad file descriptor: apr pollsetpoll: (listen)
piped logspawn: unable to setup child process '/usr/sbin/rotatelogs "/Services/Laughing Boot/Sites/Logs/defaultsite/accesslog" 604800 -420': Too many open files
Unable to open logs
[Wed Mar 19 17:01:20 2008] [warn] pid file /var/run/httpd.pid overwritten -- Unclean shutdown of previous Apache run?
[Wed Mar 19 17:01:20 2008] [error] (24)Too many open files: could not create /var/run/httpd.pid
[Wed Mar 19 17:01:20 2008] [error] httpd: could not log pid to file /var/run/httpd.pid

The last three lines repeat, ad infinitum.

I have forty-some sites, and if I disable all but 33 of them, the problem vanishes. Enable 34, and the above fit ensues.

As you can no doubt tell, this all a bit over my head. I'm pounding my head against the espresso machine and shortly will begin moaning about how God hates me.

Anyone care to at least point me in the right direction?

Thanks,
Bryan

G5 DP 2.5 ghz, etc., Mac OS X (10.5.2), OS X Server 10.5.2

Posted on Mar 19, 2008 5:11 PM

Reply
21 replies

Jun 19, 2008 7:47 PM in response to R Bryan Harrison

Just following up my previous posts and the solution we found to work with the 'Too Many Open Files' error, maybe it will help others as well.

The problem seems to be in the way Apple has changed the files/proc settings for Leopard. Using the 'ulimit' and 'sysctl' options to adjust the settings no longer works.

The option you have to use is the 'launchctl limit' command, which also adjusts both the 'ulimit' and the 'sysctl' settings automatically.

To check your existing settings, you can use the command 'launchctl limit', this shows that the server is ridiculously set at a very low maxfiles of 256 files per user/process.

Three columns will be returned, the first column displayed will be the name of the limit setting, you are looking for the 'maxproc' and/or 'maxfiles' settings towards the bottom of the list.

To increase the maxfiles you can use the command 'launchctl limit maxfiles [user max] [system max]', where [user max] is the maximum files you want to allow for each user/process and likewise for [system max].

An example would be (running as super user): launchctl limit maxfiles 2048 unlimited

We first increased this to 2048 unlimited as Apple states in the manual that the Server Admin app is supposed to change the soft process limit from 100 (the default) to 2048 when starting Apache, obviously this is not happening and the default is set to 256, so the manual is out of date or wrong. We did however still find infrequent 'too many open files' errors in apache logs so again increased the limit, this time to 4096 unlimited and have not had a problem since.

The same applies to the maxproc setting if you need additional processes.

You can verify the changes by using the 'ulimit -a' and/or 'sysctl -a | grep files' commands.

To make the changes stick through a restart, you need to add a file (as it doesn't exist) by using something like 'sudo pico /etc/launchd.conf' and add the changes one per line, so in our case, our file looks like this:

limit maxfiles 4096 unlimited

Remember you do not need to add 'launchctl' in front of the commands in this file.

Hope this helps others with this problem, we have not upgraded to 10.5.3 yet, now that things are working in 10.5.2 we will have to setup a test environment before applying anymore potential fuel to the fire!

Jun 24, 2008 12:35 AM in response to Paul Vail

@Paul Vail: To make the changes stick through a restart, you need to add a file (as it doesn't exist) by using something like 'sudo pico /etc/launchd.conf' and add the changes one per line...

It resides in /etc directory and Apache doesn't load it or need any adjustments as it is a system limitation causing the problem and once you've made the change/s Apache can run free like the wind 😉

Jun 24, 2008 6:57 PM in response to ILBT

Using /etc/launchd.conf to change launchd limits will change things for all processes, which some might consider overkill. For those who just want to raise the limit for a single service started by launchd, try modifying the launchd plist file (eg. /System/Library/LaunchDaemon/org.apache.httpd.plist) to set the soft and hard limits. The com.apple.metadata.mds.plist gives an example of how to increase the NumberOfFiles limit to 1024.

Jun 26, 2008 4:55 AM in response to Dean Huxley

Thanks for the tip Dean Huxley 🙂 There is a typo in the location of your post, it should be /System/Library/LaunchDaemonS/org.apache.httpd.plist (there is an 's' on the end of LaunchDaemons).

The only concern we have with this solution is that files in /System/Library/LaunchDaemons are installed by Apple and can/will be overwritten on updates/upgrades?

Is there another solution to avoid this happening and only raise the limits for a single service?

Jun 26, 2008 6:31 PM in response to ILBT

Well, in theory, you might be able to copy the plist file to /Library/LaunchDaemons and disable the System one, but I suspect you wouldn't be able to use serveradmin to start and stop apache, etc. (I haven't tried it).

I really don't find it that hard to overwrite/patch the plist file after an upgrade. It probably wouldn't be too hard to write a script to do it. I normally just do a 'diff -r' with the LaunchDaemons directory compared against a time machine backup to see if anything changed after an update, then I put in my own changes if needed.

420 Too Many Open Files

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple ID.