diff options
author | William Hubbs <w.d.hubbs@gmail.com> | 2017-09-14 10:38:10 -0500 |
---|---|---|
committer | William Hubbs <w.d.hubbs@gmail.com> | 2017-09-14 10:38:10 -0500 |
commit | 457f928e793cb1f6ef254935ad07f58b8762c72f (patch) | |
tree | d966829a69958c44f3e153ab5f1392e315c59e15 /sh/rc-cgroup.sh.in | |
parent | a71a461e452a98554346c47411e9c9012023c201 (diff) |
add support for control groups version 2
This is for #94.
Diffstat (limited to 'sh/rc-cgroup.sh.in')
-rw-r--r-- | sh/rc-cgroup.sh.in | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/sh/rc-cgroup.sh.in b/sh/rc-cgroup.sh.in index 5987f966..40501f22 100644 --- a/sh/rc-cgroup.sh.in +++ b/sh/rc-cgroup.sh.in @@ -152,3 +152,54 @@ cgroup_cleanup() kill -9 $pids eend $(cgroup_running && echo 1 || echo 0) "fail to stop all processes" } + +cgroup2_find_path() +{ + case "${rc_cgroup_mode:-hybrid}" in + hybrid) printf "/sys/fs/cgroup/unified" ;; + unified) printf "/sys/fs/cgroup" ;; + esac + return 0 +} + +cgroup2_remove() +{ + local cgroup_path="$(cgroup2_find_path)" rc_cgroup_path + [ -z "${cgroup_path}" ] && return 0 + rc_cgroup_path="${cgroup_path}/${RC_SVCNAME}" + [ ! -d "${rc_cgroup_path}" ] || + [ ! -e "${rc_cgroup_path}"/cgroup.events ] && + return 0 + grep -qx "$$" "${rc_cgroup_path}/cgroup.procs" && + echo 0 > "${cgroup_path}/cgroup.procs" + local key populated vvalue + while read key value; do + case "${key}" in + populated) populated=${value} ;; + *) ;; + esac + done < "${rc_cgroup_path}/cgroup.events" + [ "${populated}" = 1 ] && return 0 + rmdir "${rc_cgroup_path}" + return 0 +} + +cgroup2_set_limits() +{ + local cgroup_path="$(cgroup2_find_path)" + [ -z "${cgroup_path}" ] && return 0 + rc_cgroup_path="${cgroup_path}/${RC_SVCNAME}" + local OIFS="$IFS" + IFS=" +" + [ ! -d "${rc_cgroup_path}" ] && mkdir "${rc_cgroup_path}" + echo 0 > "${rc_cgroup_path}/cgroup.procs" + echo "${rc_cgroup_settings}" | while IFS="$OIFS" read key value; do + [ -z "${key}" ] || [ -z "${value}" ] && continue + [ ! -e "${rc_cgroup_path}/${key}" ] && continue + veinfo "${RC_SVCNAME}: cgroups: ${key} ${value}" + echo "${value}" > "${rc_cgroup_path}/${key}" + done + IFS="$OIFS" + return 0 +} |