Modifying ulimits in SystemD Unit Files



Published: 2020-08-29 07:38:16 +0000
Categories: Misc,

Language

Misc

Description

When creating a unit file for a service, it's possible to increase various limits - Max number of File Descriptors etc - so that if your service is busy it doesn't end up exhausting the resources available to it.

This snippet details the directives and their ulimit equivalents.

A full (and hopefully up to date) list can be found in the SystemD documentation.

Snippet

Directive        ulimit equivalent     Unit
LimitCPU=        ulimit -t             Seconds      
LimitFSIZE=      ulimit -f             Bytes
LimitDATA=       ulimit -d             Bytes
LimitSTACK=      ulimit -s             Bytes
LimitCORE=       ulimit -c             Bytes
LimitRSS=        ulimit -m             Bytes
LimitNOFILE=     ulimit -n             Number of File Descriptors 
LimitAS=         ulimit -v             Bytes
LimitNPROC=      ulimit -u             Number of Processes 
LimitMEMLOCK=    ulimit -l             Bytes
LimitLOCKS=      ulimit -x             Number of Locks 
LimitSIGPENDING= ulimit -i             Number of Queued Signals 
LimitMSGQUEUE=   ulimit -q             Bytes
LimitNICE=       ulimit -e             Nice Level 
LimitRTPRIO=     ulimit -r             Realtime Priority  
LimitRTTIME=     No equivalent

Usage Example

[Unit]
Description=A system unit file
After=multi-user.target

[Service]
LIMITNOFILE=4096
WorkingDirectory=/usr/local/src/bensexample
Type=idle
ExecStart=/usr/bin/python3 /usr/local/src/bensexample/count_fds.py
Restart=always
RestartSec=3

[Install]
WantedBy=multi-user.target

Keywords

systemd, ulimit, file handles, descriptors, fds, unit,

Latest Posts


Copyright © 2020 Ben Tasker | Sitemap | Privacy Policy
Available at snippets.bentasker.co.uk and http://phecoopwm6x7azx26ctuqcp6673bbqkrqfeoiz2wwk36sady5tqbdpqd.onion