-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathremove_cgroup_hier.sh
executable file
·46 lines (34 loc) · 1.32 KB
/
remove_cgroup_hier.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#!/bin/sh
#
# Usage: sh remove_cgroup_hier.sh <cgroup-v1-mount-point>
#
# In preparation for a clean unmount of the specified cgroup hierarchy,
# move all processes to the root cgroup, and remove all child cgroups.
# The main use for doing this is to ensure that a cgroup v1 directory
# is properly unmounted so that the corresponding controller becomes
# available in the cgroups v2 unified hierarchy.
cd $1
# Generate a list of the cgroup.procs files in the subdirectories
cgroup_procs_files=$(find */ -name cgroup.procs 2> /dev/null)
# Maybe there were no directories (or, the given pathname was not actually
# a cgroup v1 mount point). In that case, we have nothing to do.
if test $(echo $cgroup_procs_files | wc -w) -eq 0; then
echo "Nothing to be done!"
exit
fi
# Read the cgroup.procs files to get a list of PIDs
pids=$(cat $cgroup_procs_files | sort)
# Move each PID to the root cgroup ($1/cgroup.procs)
for p in $pids ; do
echo $p > cgroup.procs 2> /dev/null
if test $? -ne 0; then
echo -n "Error moving PID $p to root cgroup"
if test $(ps $p | wc -l) -lt 2; then
echo -n " (process appears to have already terminated)"
fi
echo
fi
done
# Remove all of the child cgroup directories. This needs to be done in a
# bottom-up fashion, so we reverse sort the set of directory pathnames.
rmdir $(find */ -type d | sort -r)