Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Increase max open files for Ubuntu/Upstart (initctl)

This is on an Ubuntu 12.04.3 LTS server.

I've added the following to /etc/security/limits.conf (my Golang processes run as root):

*      hard   nofile   50000
*      soft   nofile   50000
root   hard   nofile   50000
root   soft   nofile   50000

I've added the following to /etc/pam.d/common-session

session required pam_limits.so

I've added the following to /etc/sysctl.conf:

fs.file-max = 50000

Yet when I cat /proc/{PID}/limits, I get:

Limit                     Soft Limit           Hard Limit           Units     
Max open files            1024                 4096                 files     

This happens only when I start the process from Upstart via sudo initctl start service_name. If I start the process myself, it acknowledges my settings.

How do I fix this?

like image 504
Allison A Avatar asked Nov 15 '13 07:11

Allison A


People also ask

What is Ubuntu Upstart mode?

Upstart is an event-based replacement for the /sbin/init daemon which handles starting of tasks and services during boot, stopping them during shutdown and supervising them while the system is running.


1 Answers

This needs to be added to your Upstart script for it to work:

limit nofile 50000 50000

"It's by design that upstart does not look at /etc/security/limits.conf for system jobs. PAM settings are only applied to user sessions, not to system services." from https://bugs.launchpad.net/ubuntu/+source/upstart/+bug/938669

Sources:

https://github.com/saltstack/salt/issues/5323

http://bryanmarty.com/blog/2012/02/10/setting-nofile-limit-upstart/

like image 99
Allison A Avatar answered Oct 09 '22 11:10

Allison A