I need to increase ulimit -n on Ubuntu 12.04. It's currently:

open files                      (-n) 1024

(1024 soft, 4096 hard)

In /etc/security/limits.conf I have:

root soft nofile 10240
root hard nofile 10240

In /etc/pam.d/login, /etc/pam.d/common-session, /etc/pam.d/common-session-noninteractive I have

session    required   pam_limits.so

However, ulimit -n keeps resetting to 1024. I need to increase it as I use Node.js / socket.io with forever and the limit is limiting the maximum of concurrent visitors / connections.

  • 1
    Keeps resetting when? At reboot? Every hour? Randomly? – Daniel Widrick Sep 23 '13 at 8:22
  • 1
    @gladoscc - Did you figure this out in the end? – UpTheCreek Dec 9 '13 at 11:21

How do you start your program?

Try to wrap the start code for your program with something like this:

/bin/bash -c "ulimit -n 4096; exec /usr/bin/node /PATH_TO/YOUR_PROGRAM.js"
  • 1
    I'm using forever to start the program. – apscience Sep 23 '13 at 14:41

Do you have anything like /etc/limits.d/* ? Have you tried turning SELinux off (if you have it turned on)?

  • No. I don't have selinux. – apscience Sep 23 '13 at 10:20

Add ulimit -n 10240 to /root/.bashrc

  • This'll affect forever / node.js? – apscience Sep 23 '13 at 14:41
  • 1
    It will persist forever but only affect things running in bash using root's profile and executing the .bashrc. – Falcon Momot Sep 24 '13 at 1:53
  • You shouldn't really be running node as root in production – UpTheCreek Dec 9 '13 at 12:39

The same problem exists in Debian 8, when Im running Redis via the init script it came with. Lost 16 hours writing configs & rebooting trying to get past the limit of 1020 connections running as non-root. Im going to run it as root. AFAIK the apache server is working this way: starts as root, sets the process limits & drops the uid to www-data.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.