Linux – ulimit -n not persisting, tried everything

linuxUbuntuulimit

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.

Best Answer

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"