Setting the nofile limit in upstart

While working on a Java project that executes multiple sub processes, I found it necessary to increase to the file descriptor limit. By default, processes spawned in Ubuntu had a limit of 1024 open files, but changing that limit via ulimit or by /etc/security/limits.conf had no effect. I discovered that changes in /etc/security/limits.conf (and subsequently /etc/pam.d/common-session ) are only applied to process spawned by a login shell. Programs that launch on startup via “upstart” do not get these limits applied to them. Thankfully, upstart provides the limit stanza that allows you to modify some of these parameters, including the maximum number of open files. To see the limits on process, grab its PID, and cat /proc/<<PID>>/limits

The following is an example of increase the maximum number of open files to 4096 for a given upstart job:

limit nofile 4096 4096

You can checkout the full set of limit options at: http://upstart.ubuntu.com/wiki/Stanzas#limit

Note: Some of these limits (if not all) are transferred to any children that are forked by the parent

Check out upstart at: http://upstart.ubuntu.com/

Comments

  1. Eric S says:

    Thanks for the tip, took me a few hours to realize this fact.

  2. rad_g says:

    Thank you sir. Very helpful.

  3. zh99998 says:

    which file should i put “limit nofile 4096 4096″ into?
    only can apply to one service? or globally

  4. dave says:

    Thanks very much for this. I spent several hours trying to figure out why I was hitting these limits even though every last setting had been adjusted to allow for more open FDs (or so I thought).

Speak Your Mind

*