1212
1313monit_isolation_classid=2958295041
1414
15+ # True when /sys/fs/cgroup is the root of a cgroup2 mount (unified hierarchy).
16+ # Do not use /proc/self/cgroup's "0::" entry alone: under systemd hybrid mode a
17+ # 0:: line can refer to the small cgroup2 tracking hierarchy while resource
18+ # controllers (including net_cls) remain on cgroup v1.
19+ #
20+ # Prefer cgroup.controllers; also accept stat(2) filesystem type for hosts where
21+ # the file is missing from the mount view but the root is still cgroup2fs.
22+ monit_using_unified_cgroup_v2 () {
23+ [ -f /sys/fs/cgroup/cgroup.controllers ] && return 0
24+ [ " $( stat -fc %T /sys/fs/cgroup 2> /dev/null) " = " cgroup2fs" ]
25+ }
26+
1527permit_monit_access () {
16- if grep -q ' ^0:: ' /proc/self/cgroup 2> /dev/null ; then
28+ if monit_using_unified_cgroup_v2 ; then
1729 # cgroupv2 (unified hierarchy)
1830 # Create a sub-cgroup under the current process's cgroup and move into it.
1931 # The iptables rules match on this cgroup path.
@@ -28,15 +40,10 @@ permit_monit_access() {
2840 mkdir -p " ${monit_access_cgroup} "
2941 echo $$ > " ${monit_access_cgroup} /cgroup.procs"
3042 else
31- # cgroupv1 - use net_cls classid
32- net_cls_location=" $( cat /proc/self/mounts | grep ^cgroup | grep net_cls | awk ' { print $2 }' ) "
33- net_cls_subproc=" $( grep net_cls /proc/self/cgroup | awk -F " :" ' { print $3 }' ) "
34- if [ -z " ${net_cls_location} " ] || [ -z " ${net_cls_subproc} " ]; then
35- echo " permit_monit_access: unable to resolve cgroup v1 net_cls location or path" >&2
36- return 1
37- fi
43+ # this seems to work in docker but net_cls_location is empty in garden
44+ net_cls_location=" $( cat /proc/self/mounts | grep ^cgroup | grep net_cls | awk ' { print $2 }' ) "
45+ net_cls_subproc=" $( grep net_cls /proc/self/cgroup | awk -F " :" ' { print $3 }' ) "
3846 monit_access_cgroup=" ${net_cls_location} /${net_cls_subproc} /monit-api-access"
39-
4047 mkdir -p " ${monit_access_cgroup} "
4148 echo " ${monit_isolation_classid} " > " ${monit_access_cgroup} /net_cls.classid"
4249 echo $$ > " ${monit_access_cgroup} /tasks"
0 commit comments