#!/bin/env sh

mkdir -p /sys/fs/cgroup
mountpoint -q /sys/fs/cgroup || mount -t cgroup2 -o nsdelegate cgroup2 /sys/fs/cgroup

# just in case
[ -e "/sys/fs/cgroup/cgroup.subtree_control" ] || exit 0
[ -e "/sys/fs/cgroup/cgroup.controllers" ] || exit 0
 
# get the available controllers
read -r CG_ACTIVE < "/sys/fs/cgroup/cgroup.controllers"

# enable them individually; if some fail, that's ok
# we want to enable things here as it may not be possible later
# (e.g. cpu will not enable when there are any rt processes running)
for cont in ${CG_ACTIVE}; do
    echo "+${cont}" > "/sys/fs/cgroup/cgroup.subtree_control" 2>/dev/null || :
done
