Files
CyberPanel/packages/models.py

29 lines
1.3 KiB
Python
Raw Normal View History

2025-08-01 14:56:30 +05:00
# -*- coding: utf-8 -*-
from loginSystem.models import Administrator
from django.db import models
# Create your models here.
class Package(models.Model):
admin = models.ForeignKey(Administrator,on_delete=models.CASCADE)
packageName = models.CharField(max_length=50,unique=True)
diskSpace = models.IntegerField()
bandwidth = models.IntegerField()
emailAccounts = models.IntegerField(null=True)
dataBases = models.IntegerField(default=0)
ftpAccounts = models.IntegerField(default=0)
allowedDomains = models.IntegerField(default=0)
allowFullDomain = models.IntegerField(default=1)
enforceDiskLimits = models.IntegerField(default=0)
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
# Resource Limits - enforced via cgroups v2 and OpenLiteSpeed
memoryLimitMB = models.IntegerField(default=1024, help_text="Memory limit in MB")
cpuCores = models.IntegerField(default=1, help_text="Number of CPU cores")
ioLimitMBPS = models.IntegerField(default=10, help_text="I/O limit in MB/s")
inodeLimit = models.IntegerField(default=400000, help_text="Maximum number of files/directories")
maxConnections = models.IntegerField(default=10, help_text="Max concurrent PHP connections")
procSoftLimit = models.IntegerField(default=400, help_text="Soft process limit")
procHardLimit = models.IntegerField(default=500, help_text="Hard process limit")