#!/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
