Compare commits
1 Commits
master
...
cgroup-nam
| Author | SHA1 | Date | |
|---|---|---|---|
| db5559bb50 |
@@ -201,6 +201,9 @@ rc_tty_number=12
|
|||||||
# "unified" mounts cgroups version 2 on /sys/fs/cgroup
|
# "unified" mounts cgroups version 2 on /sys/fs/cgroup
|
||||||
#rc_cgroup_mode="unified"
|
#rc_cgroup_mode="unified"
|
||||||
|
|
||||||
|
# override cgroup controller name
|
||||||
|
#rc_cgroup_name=openrc
|
||||||
|
|
||||||
# This is a list of controllers which should be enabled for cgroups version 2
|
# This is a list of controllers which should be enabled for cgroups version 2
|
||||||
# when hybrid mode is being used.
|
# when hybrid mode is being used.
|
||||||
# Controllers listed here will not be available for cgroups version 1.
|
# Controllers listed here will not be available for cgroups version 1.
|
||||||
|
|||||||
@@ -13,6 +13,8 @@ description="Mount the control groups."
|
|||||||
|
|
||||||
: "${cgroup_opts:="nodev,noexec,nosuid"}"
|
: "${cgroup_opts:="nodev,noexec,nosuid"}"
|
||||||
|
|
||||||
|
rc_cgroup_name=${rc_cgroup_name:-openrc}
|
||||||
|
|
||||||
depend()
|
depend()
|
||||||
{
|
{
|
||||||
keyword -docker -prefix -systemd-nspawn -vserver
|
keyword -docker -prefix -systemd-nspawn -vserver
|
||||||
@@ -29,13 +31,13 @@ cgroup1_base()
|
|||||||
eend $?
|
eend $?
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if ! mountinfo -q /sys/fs/cgroup/openrc; then
|
if ! mountinfo -q /sys/fs/cgroup/"${rc_cgroup_name}"; then
|
||||||
local agent="${RC_LIBEXECDIR}/sh/cgroup-release-agent.sh"
|
local agent="${RC_LIBEXECDIR}/sh/cgroup-release-agent.sh"
|
||||||
mkdir /sys/fs/cgroup/openrc
|
mkdir /sys/fs/cgroup/"${rc_cgroup_name}"
|
||||||
mount -n -t cgroup \
|
mount -n -t cgroup \
|
||||||
-o none,${cgroup_opts},name=openrc,release_agent="$agent" \
|
-o none,${cgroup_opts},name="${rc_cgroup_name}",release_agent="$agent" \
|
||||||
openrc /sys/fs/cgroup/openrc
|
"${rc_cgroup_name}" /sys/fs/cgroup/"${rc_cgroup_name}"
|
||||||
printf 1 > /sys/fs/cgroup/openrc/notify_on_release
|
printf 1 > /sys/fs/cgroup/"${rc_cgroup_name}"/notify_on_release
|
||||||
fi
|
fi
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
@@ -74,6 +76,7 @@ cgroup2_base()
|
|||||||
mkdir -p "${base}"
|
mkdir -p "${base}"
|
||||||
mount -t cgroup2 none -o "${cgroup_opts},nsdelegate" "${base}" 2> /dev/null ||
|
mount -t cgroup2 none -o "${cgroup_opts},nsdelegate" "${base}" 2> /dev/null ||
|
||||||
mount -t cgroup2 none -o "${cgroup_opts}" "${base}"
|
mount -t cgroup2 none -o "${cgroup_opts}" "${base}"
|
||||||
|
mkdir -p ${base}/"${rc_cgroup_name}"
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -81,7 +84,7 @@ cgroup2_controllers()
|
|||||||
{
|
{
|
||||||
grep -qw cgroup2 /proc/filesystems || return 0
|
grep -qw cgroup2 /proc/filesystems || return 0
|
||||||
local active cgroup_path x y
|
local active cgroup_path x y
|
||||||
cgroup_path="$(cgroup2_find_path)"
|
cgroup_path="$(cgroup2_find_path)/${rc_cgroup_name}"
|
||||||
[ -z "${cgroup_path}" ] && return 0
|
[ -z "${cgroup_path}" ] && return 0
|
||||||
[ ! -e "${cgroup_path}/cgroup.controllers" ] && return 0
|
[ ! -e "${cgroup_path}/cgroup.controllers" ] && return 0
|
||||||
[ ! -e "${cgroup_path}/cgroup.subtree_control" ]&& return 0
|
[ ! -e "${cgroup_path}/cgroup.subtree_control" ]&& return 0
|
||||||
|
|||||||
@@ -12,7 +12,7 @@
|
|||||||
# This file may not be copied, modified, propagated, or distributed
|
# This file may not be copied, modified, propagated, or distributed
|
||||||
# except according to the terms contained in the LICENSE file.
|
# except according to the terms contained in the LICENSE file.
|
||||||
|
|
||||||
cgroup=/sys/fs/cgroup/openrc
|
cgroup=/sys/fs/cgroup/"${rc_cgroup_name:-openrc}"
|
||||||
PATH=/bin:/usr/bin:/sbin:/usr/sbin
|
PATH=/bin:/usr/bin:/sbin:/usr/sbin
|
||||||
if [ -d ${cgroup}/"$1" ]; then
|
if [ -d ${cgroup}/"$1" ]; then
|
||||||
rmdir ${cgroup}/"$1"
|
rmdir ${cgroup}/"$1"
|
||||||
|
|||||||
@@ -11,6 +11,8 @@
|
|||||||
extra_stopped_commands="${extra_stopped_commands} cgroup_cleanup"
|
extra_stopped_commands="${extra_stopped_commands} cgroup_cleanup"
|
||||||
description_cgroup_cleanup="Kill all processes in the cgroup"
|
description_cgroup_cleanup="Kill all processes in the cgroup"
|
||||||
|
|
||||||
|
cg2_sv_name="${RC_SVCNAME}.sv"
|
||||||
|
|
||||||
cgroup_find_path()
|
cgroup_find_path()
|
||||||
{
|
{
|
||||||
local OIFS name dir result
|
local OIFS name dir result
|
||||||
@@ -35,9 +37,9 @@ cgroup_get_pids()
|
|||||||
cgroup_pids=
|
cgroup_pids=
|
||||||
cgroup_procs="$(cgroup2_find_path)"
|
cgroup_procs="$(cgroup2_find_path)"
|
||||||
if [ -n "${cgroup_procs}" ]; then
|
if [ -n "${cgroup_procs}" ]; then
|
||||||
cgroup_procs="${cgroup_procs}/openrc.${RC_SVCNAME}/cgroup.procs"
|
cgroup_procs="${cgroup_procs}/${rc_cgroup_name}/${cg2_sv_name}/cgroup.procs"
|
||||||
else
|
else
|
||||||
cgroup_procs="/sys/fs/cgroup/openrc/${RC_SVCNAME}/tasks"
|
cgroup_procs="/sys/fs/cgroup/"${rc_cgroup_name}"/${RC_SVCNAME}/tasks"
|
||||||
fi
|
fi
|
||||||
[ -f "${cgroup_procs}" ] || return 0
|
[ -f "${cgroup_procs}" ] || return 0
|
||||||
while read -r p; do
|
while read -r p; do
|
||||||
@@ -51,7 +53,7 @@ cgroup_running()
|
|||||||
{
|
{
|
||||||
[ -d "/sys/fs/cgroup/unified/${RC_SVCNAME}" ] ||
|
[ -d "/sys/fs/cgroup/unified/${RC_SVCNAME}" ] ||
|
||||||
[ -d "/sys/fs/cgroup/${RC_SVCNAME}" ] ||
|
[ -d "/sys/fs/cgroup/${RC_SVCNAME}" ] ||
|
||||||
[ -d "/sys/fs/cgroup/openrc/${RC_SVCNAME}" ]
|
[ -d "/sys/fs/cgroup/"${rc_cgroup_name}"/${RC_SVCNAME}" ]
|
||||||
}
|
}
|
||||||
|
|
||||||
cgroup_set_values()
|
cgroup_set_values()
|
||||||
@@ -61,7 +63,7 @@ cgroup_set_values()
|
|||||||
local controller h
|
local controller h
|
||||||
controller="$1"
|
controller="$1"
|
||||||
h=$(cgroup_find_path "$1")
|
h=$(cgroup_find_path "$1")
|
||||||
cgroup="/sys/fs/cgroup/${1}${h}openrc_${RC_SVCNAME}"
|
cgroup="/sys/fs/cgroup/${1}${h}"${rc_cgroup_name}"_${RC_SVCNAME}"
|
||||||
[ -d "$cgroup" ] || mkdir -p "$cgroup"
|
[ -d "$cgroup" ] || mkdir -p "$cgroup"
|
||||||
|
|
||||||
set -- $2
|
set -- $2
|
||||||
@@ -108,7 +110,7 @@ cgroup_add_service()
|
|||||||
[ -w "${d}"/tasks ] && printf "%d" 0 > "${d}"/tasks
|
[ -w "${d}"/tasks ] && printf "%d" 0 > "${d}"/tasks
|
||||||
done
|
done
|
||||||
|
|
||||||
openrc_cgroup=/sys/fs/cgroup/openrc
|
openrc_cgroup=/sys/fs/cgroup/"${rc_cgroup_name}"
|
||||||
if [ -d "$openrc_cgroup" ]; then
|
if [ -d "$openrc_cgroup" ]; then
|
||||||
cgroup="$openrc_cgroup/$RC_SVCNAME"
|
cgroup="$openrc_cgroup/$RC_SVCNAME"
|
||||||
mkdir -p "$cgroup"
|
mkdir -p "$cgroup"
|
||||||
@@ -167,7 +169,7 @@ cgroup2_remove()
|
|||||||
local cgroup_path rc_cgroup_path
|
local cgroup_path rc_cgroup_path
|
||||||
cgroup_path="$(cgroup2_find_path)"
|
cgroup_path="$(cgroup2_find_path)"
|
||||||
[ -z "${cgroup_path}" ] && return 0
|
[ -z "${cgroup_path}" ] && return 0
|
||||||
rc_cgroup_path="${cgroup_path}/openrc.${RC_SVCNAME}"
|
rc_cgroup_path="${cgroup_path}/${rc_cgroup_name}/${cg2_sv_name}"
|
||||||
[ ! -d "${rc_cgroup_path}" ] ||
|
[ ! -d "${rc_cgroup_path}" ] ||
|
||||||
[ ! -e "${rc_cgroup_path}"/cgroup.events ] &&
|
[ ! -e "${rc_cgroup_path}"/cgroup.events ] &&
|
||||||
return 0
|
return 0
|
||||||
@@ -191,7 +193,7 @@ cgroup2_set_limits()
|
|||||||
cgroup_path="$(cgroup2_find_path)"
|
cgroup_path="$(cgroup2_find_path)"
|
||||||
[ -z "${cgroup_path}" ] && return 0
|
[ -z "${cgroup_path}" ] && return 0
|
||||||
mountinfo -q "${cgroup_path}"|| return 0
|
mountinfo -q "${cgroup_path}"|| return 0
|
||||||
rc_cgroup_path="${cgroup_path}/openrc.${RC_SVCNAME}"
|
rc_cgroup_path="${cgroup_path}/${rc_cgroup_name}/${cg2_sv_name}"
|
||||||
[ ! -d "${rc_cgroup_path}" ] && mkdir "${rc_cgroup_path}"
|
[ ! -d "${rc_cgroup_path}" ] && mkdir "${rc_cgroup_path}"
|
||||||
[ -f "${rc_cgroup_path}"/cgroup.procs ] &&
|
[ -f "${rc_cgroup_path}"/cgroup.procs ] &&
|
||||||
printf 0 > "${rc_cgroup_path}"/cgroup.procs
|
printf 0 > "${rc_cgroup_path}"/cgroup.procs
|
||||||
@@ -210,7 +212,7 @@ cgroup2_kill_cgroup() {
|
|||||||
local cgroup_path
|
local cgroup_path
|
||||||
cgroup_path="$(cgroup2_find_path)"
|
cgroup_path="$(cgroup2_find_path)"
|
||||||
[ -z "${cgroup_path}" ] && return 1
|
[ -z "${cgroup_path}" ] && return 1
|
||||||
rc_cgroup_path="${cgroup_path}/openrc.${RC_SVCNAME}"
|
rc_cgroup_path="${cgroup_path}/${rc_cgroup_name}/${cg2_sv_name}"
|
||||||
if [ -f "${rc_cgroup_path}"/cgroup.kill ]; then
|
if [ -f "${rc_cgroup_path}"/cgroup.kill ]; then
|
||||||
printf "%d" 1 > "${rc_cgroup_path}"/cgroup.kill
|
printf "%d" 1 > "${rc_cgroup_path}"/cgroup.kill
|
||||||
fi
|
fi
|
||||||
|
|||||||
Reference in New Issue
Block a user