#!/bin/bash
# info: delete all cgroups
# options: NONE
#
# example: v-delete-sys-cgroups
#
# This function disables cgroups

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

# Revert cgroup for all users
for user in $("$BIN/v-list-users" list); do
	user_id=$(id -u "$user")
	user_slice="user-${user_id}.slice"
	systemctl revert "$user_slice"
done

# Reload daemon
systemctl daemon-reload

# Updating hestia.conf value
$BIN/v-change-sys-config-value "RESOURCES_LIMIT" "no"

#----------------------------------------------------------#
#                       Hestia                             #
#----------------------------------------------------------#

# Logging
$BIN/v-log-action "system" "Info" "Plugins" "System cgroup Enforcement disabled."
log_event "$OK" "$ARGUMENTS"

exit
