Commit Graph

2 Commits

Author SHA1 Message Date
usmannasir
6d66e5739a 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)
2025-11-11 17:27:11 +05:00
usmannasir
c679d6ab10 Add comprehensive resource limits with automatic OpenLiteSpeed cgroups setup
This commit implements per-package resource limits for CyberPanel shared hosting
using OpenLiteSpeed's native cgroups v2 integration with automatic server configuration.

Features:
- 7 new package fields: memoryLimitMB, cpuCores, ioLimitMBPS, inodeLimit,
  maxConnections, procSoftLimit, procHardLimit
- Automatic OLS cgroups setup (no manual server configuration required)
- Multi-layer enforcement: OLS config + kernel cgroups v2 + filesystem quotas
- Per-user enforcement (subdomains/addon domains share parent's limits)
- Graceful degradation if cgroups unavailable
- Automatic backup of OLS config before modification

Backend Changes:
- packages/models.py: Added 7 resource limit fields with defaults
- packages/packagesManager.py: CRUD operations for resource limits
- plogical/resourceLimits.py: NEW - Resource manager with auto-setup
  * _ensure_cgroups_enabled(): Automatic OLS cgroups configuration
  * set_user_limits(): Apply limits via lscgctl
  * remove_user_limits(): Cleanup on deletion
  * set_inode_limit(): Filesystem quota management
- plogical/vhostConfs.py: Parameterized hardcoded resource limits
- plogical/vhost.py: Updated signatures to accept resource limits
- plogical/virtualHostUtilities.py: Extract and apply package limits


Frontend Changes:
- packages/templates/packages/createPackage.html: Resource limits UI
- packages/templates/packages/modifyPackage.html: Resource limits UI
- packages/static/packages/packages.js: AngularJS controller updates

Automatic Setup Flow:
When creating a website with enforceDiskLimits=True:
1. Check kernel cgroups v2 support
2. Run lssetup if lscgctl missing
3. Enable cgroups in OLS config if needed
4. Backup and modify /usr/local/lsws/conf/httpd_config.conf
5. Graceful restart of OpenLiteSpeed
6. Apply per-user limits via lscgctl
7. Set inode quotas via setquota

Requirements:
- Linux kernel 5.2+ (cgroups v2)
- OpenLiteSpeed 1.8+ (with lsns support)
- quota tools (optional, for inode limits)

Backward Compatibility:
- Existing packages receive default values via migration
- No manual setup required for new installations
- Graceful fallback if cgroups unavailable
2025-11-11 17:14:39 +05:00