Browse Source

Enable resource limitation module when it is set to 'yes' in hestia.config

oulfr 2 years ago
parent
commit
0c8c8256db

+ 1 - 1
bin/v-add-user

@@ -266,7 +266,7 @@ if [ "$DISK_QUOTA" = 'yes' ]; then
 	$BIN/v-update-user-quota "$user"
 fi
 
-# Update cgroup
+# Update resource limitation (cgroup)
 if [ "$RESOURCES_LIMIT" = 'yes' ]; then
 	$BIN/v-update-user-cgroup "$user"
 fi

+ 7 - 3
bin/v-list-sys-config

@@ -46,6 +46,7 @@ json_list() {
 			"DEMO_MODE": "'$DEMO_MODE'",
 			"DISABLE_IP_CHECK": "'$DISABLE_IP_CHECK'",
 			"DISK_QUOTA": "'$DISK_QUOTA'",
+			"RESOURCES_LIMIT": "'$RESOURCES_LIMIT'",
 			"DNS_CLUSTER": "'$DNS_CLUSTER'",
 			"DNS_CLUSTER_SYSTEM": "'$DNS_CLUSTER_SYSTEM'",
 			"DNS_SYSTEM": "'$DNS_SYSTEM'",
@@ -189,6 +190,9 @@ shell_list() {
 	if [ -n "$DISK_QUOTA" ]; then
 		echo "Disk Quota enabled:               $DISK_QUOTA"
 	fi
+	if [ -n "$RESOURCES_LIMIT" ]; then
+		echo "Resource limit with cgroup enabled:               $RESOURCES_LIMIT"
+	fi
 	if [ -n "$LANGUAGE" ] && [ "$LANGUAGE" != 'en' ]; then
 		echo "System Language:                  $LANGUAGE"
 	fi
@@ -239,7 +243,7 @@ plain_list() {
 	echo -ne "$PROXY_SSL_PORT\t$FTP_SYSTEM\t$MAIL_SYSTEM\t$IMAP_SYSTEM\t"
 	echo -ne "$ANTIVIRUS_SYSTEM\t$ANTISPAM_SYSTEM\t$DB_SYSTEM\t"
 	echo -ne "$DNS_SYSTEM\t$DNS_CLUSTER\t$STATS_SYSTEM\t$BACKUP_SYSTEM\t"
-	echo -ne "$CRON_SYSTEM\t$DISK_QUOTA\t$FIREWALL_SYSTEM\t$FIREWALL_EXTENSION\t"
+	echo -ne "$CRON_SYSTEM\t$DISK_QUOTA\t$RESOURCES_LIMIT\t$FIREWALL_SYSTEM\t$FIREWALL_EXTENSION\t"
 	echo -ne "$FILE_MANAGER\t$REPOSITORY\t$VERSION\t$DEMO_MODE\t$RELEASE_BRANCH\t"
 	echo -ne "$SMTP_RELAY_HOST\t$SMTP_RELAY_PORT\t$SMTP_RELAY_USER\t"
 	echo -ne "$UPGRADE_SEND_EMAIL\t$UPGRADE_SEND_EMAIL_LOG\t$THEME\t$LANGUAGE\t$BACKUP_GZIP\t"
@@ -254,7 +258,7 @@ csv_list() {
 	echo -n "'PROXY_SSL_PORT','FTP_SYSTEM','MAIL_SYSTEM','IMAP_SYSTEM',"
 	echo -n "'ANTIVIRUS_SYSTEM','ANTISPAM_SYSTEM','DB_SYSTEM',"
 	echo -n "'DNS_SYSTEM','DNS_CLUSTER','STATS_SYSTEM','BACKUP_SYSTEM',"
-	echo -n "'CRON_SYSTEM','DISK_QUOTA','FIREWALL_SYSTEM',"
+	echo -n "'CRON_SYSTEM','DISK_QUOTA','RESOURCES_LIMIT','FIREWALL_SYSTEM',"
 	echo -n "'FIREWALL_EXTENSION','FILE_MANAGER','REPOSITORY',"
 	echo -n "'VERSION','DEMO_MODE','RELEASE_BRANCH',"
 	echo -n "'SMTP_RELAY','SMTP_RELAY_HOST','SMTP_RELAY_PORT','SMTP_RELAY_USER',"
@@ -268,7 +272,7 @@ csv_list() {
 	echo -n "'$PROXY_SSL_PORT','$FTP_SYSTEM','$MAIL_SYSTEM','$IMAP_SYSTEM',"
 	echo -n "'$ANTIVIRUS_SYSTEM','$ANTISPAM_SYSTEM','$DB_SYSTEM','$DNS_SYSTEM',"
 	echo -n "'$DNS_CLUSTER','$STATS_SYSTEM','$BACKUP_SYSTEM','$CRON_SYSTEM',"
-	echo -n "'$DISK_QUOTA','$FIREWALL_SYSTEM','$FIREWALL_EXTENSION','$FILE_MANAGER',"
+	echo -n "'$DISK_QUOTA','$RESOURCES_LIMIT','$FIREWALL_SYSTEM','$FIREWALL_EXTENSION','$FILE_MANAGER',"
 	echo -n "'$REPOSITORY', '$VERSION','$DEMO_MODE','$RELEASE_BRANCH',"
 	echo -n "'$SMTP_RELAY','$SMTP_RELAY_HOST','$SMTP_RELAY_PORT','$SMTP_RELAY_USER',"
 	echo -n "'$UPGRADE_SEND_EMAIL','$UPGRADE_SEND_EMAIL_LOG','$THEME','$LANGUAGE',"

+ 10 - 3
bin/v-list-users

@@ -49,6 +49,10 @@ json_list() {
         "DATABASES": "'$DATABASES'",
         "CRON_JOBS": "'$CRON_JOBS'",
         "DISK_QUOTA": "'$DISK_QUOTA'",
+        "CPU_QUOTA": "'$CPU_QUOTA'",
+        "CPU_QUOTA_PERIOD": "'$CPU_QUOTA_PERIOD'",
+        "MEMORY_LIMIT": "'$MEMORY_LIMIT'",
+        "SWAP_LIMIT": "'$SWAP_LIMIT'",
         "BANDWIDTH": "'$BANDWIDTH'",
         "NS": "'$NS'",
         "SHELL": "'$SHELL'",
@@ -118,7 +122,8 @@ plain_list() {
 		echo -ne "$BACKEND_TEMPLATE\t$PROXY_TEMPLATE\t$DNS_TEMPLATE\t"
 		echo -ne "$WEB_DOMAINS\t$WEB_ALIASES\t$DNS_DOMAINS\t$DNS_RECORDS\t"
 		echo -ne "$MAIL_DOMAINS\t$MAIL_ACCOUNTS\t$DATABASES\t$CRON_JOBS\t"
-		echo -ne "$DISK_QUOTA\t$BANDWIDTH\t$NS\t$SHELL\t$BACKUPS\t"
+		echo -ne "$DISK_QUOTA\t$CPU_QUOTA\t$CPU_QUOTA_PERIOD\t$MEMORY_LIMIT\t"
+		echo -ne "$SWAP_LIMIT\t$BANDWIDTH\t$NS\t$SHELL\t$BACKUPS\t"
 		echo -ne "$CONTACT\t$CRON_REPORTS\t$RKEY\t$ROLE\t$SUSPENDED\t"
 		echo -ne "$SUSPENDED_USERS\t$SUSPENDED_WEB\t$SUSPENDED_DNS\t"
 		echo -ne "$SUSPENDED_MAIL\t$SUSPENDED_DB\t$SUSPENDED_CRON\t"
@@ -136,7 +141,8 @@ csv_list() {
 	echo -n "USER,NAME,PACKAGE,WEB_TEMPLATE,BACKEND_TEMPLATE,"
 	echo -n "PROXY_TEMPLATE,DNS_TEMPLATE,WEB_DOMAINS,WEB_ALIASES,"
 	echo -n "DNS_DOMAINS,DNS_RECORDS,MAIL_DOMAINS,MAIL_ACCOUNTS,"
-	echo -n "DATABASES,CRON_JOBS,DISK_QUOTA,BANDWIDTH,NS,HOME,SHELL,"
+	echo -n "DATABASES,CRON_JOBS,DISK_QUOTA,CPU_QUOTA,CPU_QUOTA_PERIOD,"
+	echo -n "MEMORY_LIMIT,SWAP_LIMIT,BANDWIDTH,NS,HOME,SHELL,"
 	echo -n "BACKUPS,CONTACT,CRON_REPORTS,RKEY,ROLE,SUSPENDED,SUSPENDED_USERS,"
 	echo -n "SUSPENDED_WEB,SUSPENDED_DNS,SUSPENDED_MAIL,SUSPENDED_DB,"
 	echo -n "SUSPENDED_CRON,IP_AVAIL,IP_OWNED,U_USERS,U_DISK,U_DISK_DIRS,"
@@ -153,7 +159,8 @@ csv_list() {
 		echo -n "$BACKEND_TEMPLATE,$PROXY_TEMPLATE,$DNS_TEMPLATE,"
 		echo -n "$WEB_DOMAINS,$WEB_ALIASES,$DNS_DOMAINS,$DNS_RECORDS,"
 		echo -n "$MAIL_DOMAINS,$MAIL_ACCOUNTS,$DATABASES,$CRON_JOBS,"
-		echo -n "$DISK_QUOTA,$BANDWIDTH,\"$NS\",$HOME,$SHELL,$BACKUPS,"
+		echo -n "$DISK_QUOTA,$CPU_QUOTA,$CPU_QUOTA_PERIOD,$MEMORY_LIMIT,"
+		echo -n "$SWAP_LIMIT,$BANDWIDTH,\"$NS\",$HOME,$SHELL,$BACKUPS,"
 		echo -n "$CONTACT,$CRON_REPORTS,\"$RKEY\",$ROLE,$SUSPENDED,"
 		echo -n "$SUSPENDED_USERS,$SUSPENDED_WEB,$SUSPENDED_DNS,"
 		echo -n "$SUSPENDED_MAIL,$SUSPENDED_DB,$SUSPENDED_CRON,$IP_AVAIL,"

+ 4 - 1
web/templates/pages/add_package.php

@@ -278,7 +278,9 @@
 					</div>
 				</div>
 			</details>
-			<details class="collapse" id="system-resources-options">
+
+			<?php if ($_SESSION['RESOURCES_LIMIT'] == 'yes') { ?>
+				<details class="collapse" id="system-resources-options">
 				<summary class="collapse-header">
 					<?= _("System Resources") ?>
 				</summary>
@@ -336,6 +338,7 @@
 					</div>
 				</div>
 			</details>
+			<?php } ?>
 		</div>
 
 	</form>

+ 53 - 50
web/templates/pages/edit_package.php

@@ -289,64 +289,67 @@
 				</div>
 			</details>
 
-			<details class="collapse" id="system-resources-options">
-				<summary class="collapse-header">
-					<?= _("System Resources") ?>
-				</summary>
-				<div class="collapse-content">
-					<div class="u-mb10">
-						<label for="cfs_quota" class="form-label">
-							<?= _("CPU Quota (in %)") ?>
-						</label>
-						<div class="u-pos-relative">
-							<input type="text" class="form-control" name="v_cpu_quota" id="v_cpu_quota" value="<?= htmlentities(trim($v_cpu_quota, "'")) ?>">
-							<button type="button" class="unlimited-toggle js-unlimited-toggle" title="<?= _("Unlimited") ?>">
-								<i class="fas fa-infinity"></i>
-							</button>
+			<?php if ($_SESSION['RESOURCES_LIMIT'] == 'yes') { ?>
+				<details class="collapse" id="system-resources-options">
+					<summary class="collapse-header">
+						<?= _("System Resources") ?>
+					</summary>
+					<div class="collapse-content">
+						<div class="u-mb10">
+							<label for="cfs_quota" class="form-label">
+								<?= _("CPU Quota (in %)") ?>
+							</label>
+							<div class="u-pos-relative">
+								<input type="text" class="form-control" name="v_cpu_quota" id="v_cpu_quota" value="<?= htmlentities(trim($v_cpu_quota, "'")) ?>">
+								<button type="button" class="unlimited-toggle js-unlimited-toggle" title="<?= _("Unlimited") ?>">
+									<i class="fas fa-infinity"></i>
+								</button>
+							</div>
+							<small class="form-text text-muted"><?= _("CPUQuota=20% ensures that the executed processes will never get more than 20% CPU time on one CPU.") ?></small>
 						</div>
-						<small class="form-text text-muted"><?= _("CPUQuota=20% ensures that the executed processes will never get more than 20% CPU time on one CPU.") ?></small>
-					</div>
 
-					<div class="u-mb10">
-						<label for="cfs_period" class="form-label">
-							<?= _("CPU Quota Period (in ms for milliseconds or s for seconds.)") ?>
-						</label>
-						<div class="u-pos-relative">
-							<input type="text" class="form-control" name="v_cpu_quota_period" id="v_cpu_quota_period" value="<?= htmlentities(trim($v_cpu_quota_period, "'")) ?>">
-							<button type="button" class="unlimited-toggle js-unlimited-toggle" title="<?= _("Unlimited") ?>">
-								<i class="fas fa-infinity"></i>
-							</button>
+						<div class="u-mb10">
+							<label for="cfs_period" class="form-label">
+								<?= _("CPU Quota Period (in ms for milliseconds or s for seconds.)") ?>
+							</label>
+							<div class="u-pos-relative">
+								<input type="text" class="form-control" name="v_cpu_quota_period" id="v_cpu_quota_period" value="<?= htmlentities(trim($v_cpu_quota_period, "'")) ?>">
+								<button type="button" class="unlimited-toggle js-unlimited-toggle" title="<?= _("Unlimited") ?>">
+									<i class="fas fa-infinity"></i>
+								</button>
+							</div>
+							<small class="form-text text-muted"><?= _("CPUQuotaPeriodSec=10ms to request that the CPU quota is measured in periods of 10ms.") ?></small>
 						</div>
-						<small class="form-text text-muted"><?= _("CPUQuotaPeriodSec=10ms to request that the CPU quota is measured in periods of 10ms.") ?></small>
-					</div>
 
-					<div class="u-mb10">
-						<label for="memory_limit" class="form-label">
-							<?= _("Memory Limit (in bytes or with units like '2G')") ?>
-						</label>
-						<div class="u-pos-relative">
-							<input type="text" class="form-control" name="v_memory_limit" id="v_memory_limit" value="<?= htmlentities(trim($v_memory_limit, "'")) ?>">
-							<button type="button" class="unlimited-toggle js-unlimited-toggle" title="<?= _("Unlimited") ?>">
-								<i class="fas fa-infinity"></i>
-							</button>
+						<div class="u-mb10">
+							<label for="memory_limit" class="form-label">
+								<?= _("Memory Limit (in bytes or with units like '2G')") ?>
+							</label>
+							<div class="u-pos-relative">
+								<input type="text" class="form-control" name="v_memory_limit" id="v_memory_limit" value="<?= htmlentities(trim($v_memory_limit, "'")) ?>">
+								<button type="button" class="unlimited-toggle js-unlimited-toggle" title="<?= _("Unlimited") ?>">
+									<i class="fas fa-infinity"></i>
+								</button>
+							</div>
+							<small class="form-text text-muted"><?= _("Takes a memory size in bytes. If the value is suffixed with K, M, G or T, the specified memory size is parsed as Kilobytes, Megabytes, Gigabytes, or Terabytes (with the base 1024), respectively") ?></small>
 						</div>
-						<small class="form-text text-muted"><?= _("Takes a memory size in bytes. If the value is suffixed with K, M, G or T, the specified memory size is parsed as Kilobytes, Megabytes, Gigabytes, or Terabytes (with the base 1024), respectively") ?></small>
-					</div>
 
-					<div class="u-mb10">
-						<label for="swap_limit" class="form-label">
-							<?= _("Swap Limit (in bytes or with units like '2G')") ?>
-						</label>
-						<div class="u-pos-relative">
-							<input type="text" class="form-control" name="v_swap_limit" id="v_swap_limit" value="<?= htmlentities(trim($v_swap_limit, "'")) ?>">
-							<button type="button" class="unlimited-toggle js-unlimited-toggle" title="<?= _("Unlimited") ?>">
-								<i class="fas fa-infinity"></i>
-							</button>
+						<div class="u-mb10">
+							<label for="swap_limit" class="form-label">
+								<?= _("Swap Limit (in bytes or with units like '2G')") ?>
+							</label>
+							<div class="u-pos-relative">
+								<input type="text" class="form-control" name="v_swap_limit" id="v_swap_limit" value="<?= htmlentities(trim($v_swap_limit, "'")) ?>">
+								<button type="button" class="unlimited-toggle js-unlimited-toggle" title="<?= _("Unlimited") ?>">
+									<i class="fas fa-infinity"></i>
+								</button>
+							</div>
+							<small class="form-text text-muted"><?= _("Takes a swap size in bytes. If the value is suffixed with K, M, G or T, the specified swap size is parsed as Kilobytes, Megabytes, Gigabytes, or Terabytes (with the base 1024), respectively") ?></small>
 						</div>
-						<small class="form-text text-muted"><?= _("Takes a swap size in bytes. If the value is suffixed with K, M, G or T, the specified swap size is parsed as Kilobytes, Megabytes, Gigabytes, or Terabytes (with the base 1024), respectively") ?></small>
 					</div>
-				</div>
-			</details>
+				</details>
+			<?php } ?>
+
 		</div>
 
 	</form>