Bug 1351415

Summary: [RFE] Unable to set soft and hard limits for services under systemd
Product: Red Hat Enterprise Linux 7 Reporter: Jayaraj <jdeenada>
Component: systemdAssignee: systemd-maint
Status: CLOSED ERRATA QA Contact: Branislav Blaškovič <bblaskov>
Severity: high Docs Contact:
Priority: unspecified    
Version: 7.2CC: avaddara, bblaskov, ccheney, chey, lpol, mschena, msekleta, systemd-maint-list, systemd-maint
Target Milestone: rcKeywords: FutureFeature
Target Release: ---   
Hardware: x86_64   
OS: Linux   
Whiteboard:
Fixed In Version: systemd-219-23.el7 Doc Type: If docs needed, set a value
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2016-11-04 00:55:22 UTC Type: Bug
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:

Description Jayaraj 2016-06-30 04:02:48 UTC
Description of problem:

This is for TAM customer. The customer is in the middle of migrating 20 servers to RHEL 7 and want to configure their custom services under systemd. They are unable to set different values of soft and hard limit under systemd.
The setup works perfectly as defined in https://access.redhat.com/solutions/1346533. but the steps given in the above kcs set the soft and hard limit to same value. 


Version-Release number of selected component (if applicable):
RHEL 7.2 (3.10.0-327.10.1.el7.x86_64 )

How reproducible:
100%

Steps to Reproduce:
# mkdir /etc/systemd/system/httpd.service.d
# echo [Service] >/etc/systemd/system/httpd.service.d/ulimit.conf
# echo LimitNOFILE=8000 >>/etc/systemd/system/httpd.service.d/ulimit.conf
# echo LimitNPROC=32000 >>/etc/systemd/system/httpd.service.d/ulimit.conf
# cat /etc/systemd/system/httpd.service.d/ulimit.conf
[Service]
LimitNOFILE=8000
LimitNPROC=32000
# systemctl daemon-reload
# systemctl restart httpd
# systemctl show httpd | grep -ie nproc -e nofile
LimitNOFILE=8000
LimitNPROC=32000
# eval $(systemctl show httpd -p MainPID)
# egrep 'process|open files' /proc/$MainPID/limits
Limit                     Soft Limit           Hard Limit           Units   
Max processes             32000                32000                processes
Max open files            8000                 8000                 files

The above output shows same value for soft and hard limit. Unable to set the soft and hard limits to different values. 


Actual results:

Tried declaring the values to soft:hard in /etc/systemd/system/httpd.service.d/ulimit.conf like below but it is not getting applied and service is taking default values.
[Service]
LimitNOFILE=10240:20240
LimitNPROC=16000

Expected results:
The soft and hard limit should be of different values that are declared in /etc/systemd/system/httpd.service.d/ulimit.conf

Additional info:
Since daemons started by systemd don't employ pam login session, the limits can be set only in the service unit file. so no point of having limits defined in /etc/security/limits.conf

Comment 3 Michal Sekletar 2016-07-04 16:46:01 UTC
Already implemented upstream. We need to backport https://github.com/systemd/systemd/pull/1994 and follow-up fix-up commits.

Comment 8 Lukáš Nykrýn 2016-07-12 12:53:29 UTC
patches pushed to staging ->
core: dump rlim_cur too
https://github.com/lnykryn/systemd-rhel/commit/0c4a515

core: fix rlimit parsing
https://github.com/lnykryn/systemd-rhel/commit/b53ec8d

core: support <soft:hard> ranges for RLIMIT options
https://github.com/lnykryn/systemd-rhel/commit/81a95ec

time-util: add parse_time(), which is like parse_sec() but allows specification of default time unit if none is specified
https://github.com/lnykryn/systemd-rhel/commit/8afe425

core: accept time units for time-based resource limits
https://github.com/lnykryn/systemd-rhel/commit/128ef85

core: support IEC suffixes for RLIMIT stuff
https://github.com/lnykryn/systemd-rhel/commit/99074ee
-> post

Comment 10 Branislav Blaškovič 2016-07-28 09:03:47 UTC
Patches look sane but I am not sure how it should behave in case an admin sets incorrect limits, for example:

LimitNPROC=32000:30000 # so soft limit is greater than the hard one

Any ideas? Now it just totally ignores this line.

Comment 11 Branislav Blaškovič 2016-07-28 09:07:24 UTC
Ignoring incorrect values (for now), this bug looks fixed.

Using /CoreOS/systemd/Regression/Unable-to-set-soft-and-hard-limits-for-services

:: [   LOG    ] :: Package versions:
:: [   LOG    ] ::   systemd-219-24.el7.x86_64
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:: [   LOG    ] :: Correct limits setup
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

:: [   PASS   ] :: Command 'echo [Service] >/etc/systemd/system/httpd.service.d/ulimit.conf' (Expected 0, got 0)
:: [   PASS   ] :: Command 'echo LimitNOFILE=6000:8000 >>/etc/systemd/system/httpd.service.d/ulimit.conf' (Expected 0, got 0)
:: [   PASS   ] :: Command 'echo LimitNPROC=30000:32000 >>/etc/systemd/system/httpd.service.d/ulimit.conf' (Expected 0, got 0)
:: [   PASS   ] :: Command 'systemctl daemon-reload' (Expected 0, got 0)
:: [   LOG    ] :: rlServiceStart: Service httpd started successfully
:: [   LOG    ] :: Duration: 1s
:: [   LOG    ] :: Assertions: 4 good, 0 bad
:: [   PASS   ] :: RESULT: Correct limits setup

::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:: [   LOG    ] :: Correct limits test
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

:: [   PASS   ] :: Command 'systemctl show httpd | grep -ie nproc -e nofile' (Expected 0, got 0)
:: [   PASS   ] :: Command 'cat /proc/8632/limits' (Expected 0, got 0)
:: [   PASS   ] :: Command 'grep "Max processes[ ]\+30000[ ]\+32000[ ]\+processes" /var/tmp/tmp.35rGIpMudS' (Expected 0, got 0)
:: [   PASS   ] :: Command 'grep "Max open files[ ]\+6000[ ]\+8000[ ]\+files" /var/tmp/tmp.35rGIpMudS' (Expected 0, got 0)
:: [   LOG    ] :: Duration: 0s
:: [   LOG    ] :: Assertions: 4 good, 0 bad
:: [   PASS   ] :: RESULT: Correct limits test

::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:: [   LOG    ] :: Equal limit setup
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

:: [   PASS   ] :: Command 'echo > /etc/systemd/system/httpd.service.d/ulimit.conf' (Expected 0, got 0)
:: [   PASS   ] :: Command 'echo [Service] >/etc/systemd/system/httpd.service.d/ulimit.conf' (Expected 0, got 0)
:: [   PASS   ] :: Command 'echo LimitNOFILE=8000:8000 >>/etc/systemd/system/httpd.service.d/ulimit.conf' (Expected 0, got 0)
:: [   PASS   ] :: Command 'echo LimitNPROC=32000:32000 >>/etc/systemd/system/httpd.service.d/ulimit.conf' (Expected 0, got 0)
:: [   PASS   ] :: Command 'systemctl daemon-reload' (Expected 0, got 0)
:: [   LOG    ] :: rlServiceStart: Service httpd already running, stopping first.
:: [   LOG    ] :: rlServiceStart: Service httpd started successfully
:: [   LOG    ] :: Duration: 2s
:: [   LOG    ] :: Assertions: 5 good, 0 bad
:: [   PASS   ] :: RESULT: Equal limit setup

::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:: [   LOG    ] :: Equal limits test
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

:: [   PASS   ] :: Command 'systemctl show httpd | grep -ie nproc -e nofile' (Expected 0, got 0)
:: [   PASS   ] :: Command 'cat /proc/8852/limits' (Expected 0, got 0)
:: [   PASS   ] :: Command 'grep "Max processes[ ]\+32000[ ]\+32000[ ]\+processes" /var/tmp/tmp.8LjxkmRJzM' (Expected 0, got 0)
:: [   PASS   ] :: Command 'grep "Max open files[ ]\+8000[ ]\+8000[ ]\+files" /var/tmp/tmp.8LjxkmRJzM' (Expected 0, got 0)
:: [   LOG    ] :: Duration: 0s
:: [   LOG    ] :: Assertions: 4 good, 0 bad
:: [   PASS   ] :: RESULT: Equal limits test


Switching to verified.

Comment 15 errata-xmlrpc 2016-11-04 00:55:22 UTC
Since the problem described in this bug report should be
resolved in a recent advisory, it has been closed with a
resolution of ERRATA.

For information on the advisory, and where to find the updated
files, follow the link below.

If the solution does not work for you, open a new bug report.

https://rhn.redhat.com/errata/RHBA-2016-2216.html

Comment 18 Plumber Bot 2022-01-21 15:38:21 UTC
Dropping the stale needinfo. If our input is still needed, please set the needinfo again.