Last Updated: July 16, 2021
·
11.45K
· rparet

Setting max file descriptors and other limits with upstart on debian/ubuntu

Out of file descriptors?

If you run service jobs (daemons and the like) via upstart on debian/ubuntu you may have run into a problem where they don't inherit the settings you'd expect from ulimit / limits.conf on your box.

You may be googling and getting advice like making sure you have the right settings in /etc/security/limits.conf and making sure that session required pam_limits.so is in /etc/pam.d/common-session{,-noninteractive}.

This advice is solid for processes spawned interactively and those run from SysV init (/etc/init.d/...) however Upstart does not respect /etc/security/limits.conf or anything related to PAM by design.

Solution: Set your limits explicitly in Upstart

If you want to set limits for processes managed by Upstart, you have to do it explicitly in the Upstart config.

For example:

#
description "my service"
start on startup
stop on shutdown
# set max file descriptors to 65536 (soft/hard)
limit nofile 65536 65536

script
/path/to/my/script
end script

Hopefully this saves you a few hours of frustation when your upstart-managed process runs out of file descriptors for the first time!

2 Responses
Add your response

It works for my elasticsearch setup as well, thanks

over 1 year ago ·

This was really helpful! Thanks.

over 1 year ago ·