Skip to content

Commit 6d66e57

Browse files
committed
Add RHEL 8 family cgroups v2 detection and enablement instructions
Detect RHEL 8, AlmaLinux 8, Rocky Linux 8, and CloudLinux 8 systems and provide clear instructions when cgroups v2 needs manual enablement. These systems have cgroups v2 backported to kernel 4.18 but it's disabled by default. When detected without cgroups v2 enabled, the system now: 1. Detects RHEL 8 family by checking /etc/redhat-release 2. Verifies if cgroups v2 is mounted (checks 'mount' output for 'cgroup2') 3. If not enabled, logs detailed instructions: - grubby command to add kernel parameter - Reboot instruction - Verification command - Clear step-by-step guide Changes: - _check_rhel8_cgroups_v2(): New method for RHEL 8 family detection - _ensure_cgroups_enabled(): Calls RHEL 8 check before general checks - check_cgroup_support(): Returns RHEL 8 status in support dict - rhel8_family: bool (detected RHEL 8 family) - rhel8_needs_enablement: bool (cgroups v2 not mounted) - os_name: str (full OS name from release file) OS Support Status: ✅ Ubuntu 20.04+ - Native cgroups v2 (kernel 5.4+) ✅ RHEL/Alma/Rocky 9+ - Native cgroups v2 (kernel 5.14+) ⚠️ RHEL/Alma/Rocky/CloudLinux 8 - Needs manual enable (kernel 4.18 backported)
1 parent e61236c commit 6d66e57

File tree

1 file changed

+119
-1
lines changed

1 file changed

+119
-1
lines changed

plogical/resourceLimits.py

Lines changed: 119 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,91 @@ def __init__(self):
3434
"""Initialize the resource limits manager"""
3535
self._initialized = False
3636

37+
def _check_rhel8_cgroups_v2(self):
38+
"""
39+
Check if RHEL 8 family needs manual cgroups v2 enablement
40+
41+
RHEL 8, AlmaLinux 8, Rocky Linux 8, and CloudLinux 8 have cgroups v2
42+
backported to kernel 4.18 but it's disabled by default.
43+
44+
Returns:
45+
bool: True if cgroups v2 is available or not RHEL 8, False if needs enablement
46+
"""
47+
try:
48+
# Check if this is a RHEL 8 family system
49+
redhat_release_paths = ['/etc/redhat-release', '/etc/system-release']
50+
is_rhel8 = False
51+
os_name = "Unknown"
52+
53+
for release_file in redhat_release_paths:
54+
if os.path.exists(release_file):
55+
try:
56+
with open(release_file, 'r') as f:
57+
release_content = f.read().lower()
58+
os_name = release_content.strip()
59+
60+
# Check for RHEL 8 family (RHEL, AlmaLinux, Rocky, CloudLinux, CentOS 8)
61+
if ('release 8' in release_content or
62+
'release 8.' in release_content):
63+
if any(distro in release_content for distro in
64+
['red hat', 'almalinux', 'rocky', 'cloudlinux', 'centos']):
65+
is_rhel8 = True
66+
break
67+
except:
68+
pass
69+
70+
if not is_rhel8:
71+
# Not RHEL 8 family, no special handling needed
72+
return True
73+
74+
# This is RHEL 8 family - check if cgroups v2 is actually enabled
75+
logging.writeToFile(f"Detected RHEL 8 family system: {os_name}")
76+
77+
# Check if cgroups v2 is mounted (indicates it's enabled)
78+
try:
79+
result = subprocess.run(
80+
['mount'],
81+
capture_output=True,
82+
text=True,
83+
timeout=5
84+
)
85+
86+
if 'cgroup2' in result.stdout:
87+
logging.writeToFile("cgroups v2 is enabled on RHEL 8 family system")
88+
return True
89+
else:
90+
# cgroups v2 is not enabled - provide instructions
91+
logging.writeToFile("=" * 80)
92+
logging.writeToFile("RHEL 8 FAMILY: cgroups v2 MANUAL ENABLEMENT REQUIRED")
93+
logging.writeToFile("=" * 80)
94+
logging.writeToFile(f"System: {os_name}")
95+
logging.writeToFile(f"Kernel: {os.uname().release}")
96+
logging.writeToFile("")
97+
logging.writeToFile("RHEL 8, AlmaLinux 8, Rocky Linux 8, and CloudLinux 8 have cgroups v2")
98+
logging.writeToFile("backported but disabled by default. To enable, run these commands:")
99+
logging.writeToFile("")
100+
logging.writeToFile("1. Enable cgroups v2 in boot parameters:")
101+
logging.writeToFile(" grubby --update-kernel=ALL --args='systemd.unified_cgroup_hierarchy=1'")
102+
logging.writeToFile("")
103+
logging.writeToFile("2. Reboot the system:")
104+
logging.writeToFile(" reboot")
105+
logging.writeToFile("")
106+
logging.writeToFile("3. After reboot, verify cgroups v2 is enabled:")
107+
logging.writeToFile(" mount | grep cgroup2")
108+
logging.writeToFile("")
109+
logging.writeToFile("4. Then create websites with resource limits")
110+
logging.writeToFile("=" * 80)
111+
return False
112+
113+
except Exception as e:
114+
logging.writeToFile(f"Error checking cgroups v2 mount status: {str(e)}")
115+
return False
116+
117+
except Exception as e:
118+
logging.writeToFile(f"Error checking RHEL 8 family status: {str(e)}")
119+
# If we can't detect, assume it's OK and let the normal checks proceed
120+
return True
121+
37122
def _ensure_cgroups_enabled(self):
38123
"""
39124
Ensure OpenLiteSpeed cgroups are enabled
@@ -46,9 +131,14 @@ def _ensure_cgroups_enabled(self):
46131
return True
47132

48133
try:
134+
# Special check for RHEL 8 family systems
135+
if not self._check_rhel8_cgroups_v2():
136+
return False
137+
49138
# Check kernel support first
50139
if not os.path.exists('/sys/fs/cgroup/cgroup.controllers'):
51140
logging.writeToFile("cgroups v2 not available on this system (requires kernel 5.2+)")
141+
logging.writeToFile("For RHEL 8 family, see instructions above to enable cgroups v2")
52142
return False
53143

54144
# Check if lscgctl exists
@@ -406,10 +496,38 @@ def check_cgroup_support(self):
406496
'memory_controller': False,
407497
'cpu_controller': False,
408498
'io_controller': False,
409-
'quota_tools': False
499+
'quota_tools': False,
500+
'rhel8_family': False,
501+
'rhel8_needs_enablement': False,
502+
'os_name': 'Unknown'
410503
}
411504

412505
try:
506+
# Check for RHEL 8 family
507+
redhat_release_paths = ['/etc/redhat-release', '/etc/system-release']
508+
for release_file in redhat_release_paths:
509+
if os.path.exists(release_file):
510+
try:
511+
with open(release_file, 'r') as f:
512+
release_content = f.read()
513+
support['os_name'] = release_content.strip()
514+
515+
# Check for RHEL 8 family
516+
if ('release 8' in release_content.lower() or
517+
'release 8.' in release_content.lower()):
518+
if any(distro in release_content.lower() for distro in
519+
['red hat', 'almalinux', 'rocky', 'cloudlinux', 'centos']):
520+
support['rhel8_family'] = True
521+
522+
# Check if cgroups v2 is actually mounted
523+
result = subprocess.run(['mount'], capture_output=True,
524+
text=True, timeout=5)
525+
if 'cgroup2' not in result.stdout:
526+
support['rhel8_needs_enablement'] = True
527+
break
528+
except:
529+
pass
530+
413531
# Check cgroups v2
414532
if os.path.exists('/sys/fs/cgroup/cgroup.controllers'):
415533
support['cgroups_v2'] = True

0 commit comments

Comments
 (0)