Browse Source

Update permissions

Add cgroup support without changing config manually

Edit server page

Disable  restart
Jaap Marcus 2 years ago
parent
commit
9e54e8567d

+ 49 - 0
bin/v-add-sys-cgroups

@@ -0,0 +1,49 @@
+#!/bin/bash
+# info: Enable cgroup support for user
+# options: NONE
+#
+# example: v-add-sys-cgroup
+
+#----------------------------------------------------------#
+#                Variables & Functions                     #
+#----------------------------------------------------------#
+
+# Includes
+# shellcheck source=/etc/hestiacp/hestia.conf
+source /etc/hestiacp/hestia.conf
+# shellcheck source=/usr/local/hestia/func/main.sh
+source $HESTIA/func/main.sh
+# load config file
+source_conf "$HESTIA/conf/hestia.conf"
+
+#----------------------------------------------------------#
+#                    Verifications                         #
+#----------------------------------------------------------#
+
+# Perform verification if read-only mode is enabled
+check_hestia_demo_mode
+
+#----------------------------------------------------------#
+#                       Action                             #
+#----------------------------------------------------------#
+
+# Updating hestia.conf value
+$BIN/v-change-sys-config-value "RESOURCES_LIMIT" "yes"
+
+# enable cgroup for all users
+for user in $("$BIN/v-list-users" list); do
+	$BIN/v-update-user-cgroup "$user"
+done
+
+# Reload daemon
+systemctl daemon-reload
+
+#----------------------------------------------------------#
+#                       Hestia                             #
+#----------------------------------------------------------#
+
+# Logging
+$BIN/v-log-action "system" "Info" "Plugins" "System cgroup Enforcement Enabled."
+log_event "$OK" "$ARGUMENTS"
+
+exit

+ 2 - 0
bin/v-delete-sys-cgroup

@@ -85,6 +85,8 @@ json_list() {
 			"PROXY_SSL_PORT": "'$PROXY_SSL_PORT'",
 			"PROXY_SYSTEM": "'$PROXY_SYSTEM'",
 			"RELEASE_BRANCH": "'$RELEASE_BRANCH'",
+			"RELEASE_BRANCH": "'$RELEASE_BRANCH'",
+			"RESOURCES_LIMIT": "'$RESOURCES_LIMIT'",
 			"REPOSITORY": "'$REPOSITORY'",
       "ROOT_USER": "'$ROOT_USER'",
 			"SERVER_SMTP_ADDR": "'$SERVER_SMTP_ADDR'",

+ 1 - 0
bin/v-update-user-cgroup

@@ -73,6 +73,7 @@ fi
 
 # Apply change immediately: not needed for now
 #systemctl restart "$user_slice"
+
 #----------------------------------------------------------#
 #                       Hestia                             #
 #----------------------------------------------------------#

+ 24 - 0
web/edit/server/index.php

@@ -582,6 +582,30 @@ if (!empty($_POST["save"])) {
 		}
 	}
 
+	// Set disk_quota support
+	if (empty($_SESSION["error_msg"])) {
+		if (
+			!empty($_POST["v_resources_limit"]) &&
+			$_SESSION["RESOURCES_LIMIT"] != $_POST["v_resources_limit"]
+		) {
+			if ($_POST["v_resources_limit"] == "yes") {
+				exec(HESTIA_CMD . "v-add-sys-cgroups", $output, $return_var);
+				check_return_code($return_var, $output);
+				unset($output);
+				if (empty($_SESSION["error_msg"])) {
+					$_SESSION["RESOURCES_LIMIT"] = "yes";
+				}
+			} else {
+				exec(HESTIA_CMD . "v-delete-sys-cgroups", $output, $return_var);
+				check_return_code($return_var, $output);
+				unset($output);
+				if (empty($_SESSION["error_msg"])) {
+					$_SESSION["RESOURCES_LIMIT"] = "no";
+				}
+			}
+		}
+	}
+
 	// Set firewall support
 	if (empty($_SESSION["error_msg"])) {
 		if ($_SESSION["FIREWALL_SYSTEM"] == "iptables") {

+ 13 - 0
web/templates/pages/edit_server.php

@@ -1401,6 +1401,19 @@
 							</option>
 						</select>
 					</div>
+					<div class="u-mb10">
+						<label for="v_resources_limit" class="form-label">
+							<?= _("Limit System Resources") ?>
+						</label>
+						<select class="form-select" name="v_resources_limit" id="v_resources_limit">
+							<option value="no">
+								<?= _("No") ?>
+							</option>
+							<option value="yes" <?= $_SESSION["RESOURCES_LIMIT"] == "yes" ? "selected" : "" ?>>
+								<?= _("Yes") ?>
+							</option>
+						</select>
+					</div>
 					<div class="u-mb10">
 						<label for="v_quota" class="form-label">
 							<?= _("File System Disk Quota") ?>