Skip to content

Instantly share code, notes, and snippets.

@aliostad
Last active May 8, 2017 14:20
Embed
What would you like to do?
BASH script for increasing file descriptors on linux
MAXFILE=65536
CURRENT_MAXFILE=$(ulimit -n)
function update_sysctl(){
UPDT="fs.file-max = $MAXFILE"
if ! grep "$UPDT" /etc/sysctl.conf; then
echo "$UPDT" >> /etc/sysctl.conf
fi
}
function update_limitsconf(){
UPDT="* soft nproc $MAXFILE"
if ! grep "$UPDT" /etc/security/limits.conf; then
echo "* soft nproc $MAXFILE" >> /etc/security/limits.conf
echo "* hard nproc $MAXFILE" >> /etc/security/limits.conf
echo "* soft nofile $MAXFILE" >> /etc/security/limits.conf
echo "* hard nofile $MAXFILE" >> /etc/security/limits.conf
echo "root soft nofile $MAXFILE" >> /etc/security/limits.conf
echo "root hard nofile $MAXFILE" >> /etc/security/limits.conf
fi
}
function update_session_perm(){
UPDT="session required pam_limits.so"
if ! grep "$UPDT" /etc/pam.d/common-session; then
echo "$UPDT" >> /etc/pam.d/common-session
echo "$UPDT" >> /etc/pam.d/common-session-noninteractive
fi
}
if [ $CURRENT_MAXFILE != $MAXFILE ]; then
update_sysctl
update_limitsconf
update_session_perm
# reboot ==> MAKE SURE YOU REBOOT!!
fi
@aliostad
Copy link
Author

aliostad commented May 5, 2017

Make sure you reboot

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment