-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathInstallCGroup.bash
More file actions
executable file
·34 lines (29 loc) · 1.31 KB
/
InstallCGroup.bash
File metadata and controls
executable file
·34 lines (29 loc) · 1.31 KB
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
#!/bin/bash
#----Run this under sudo to get everything set up. The first argument is the "user name"
#----and the second argument is the "user group name" for the cgroup directory under which
#----the cgroup for the programs that run are created, using PIDs to keep them separated.
if [ "$#" -lt 2 ]; then
CGroupUserName=`id -u -n`
CGroupGroupName=`id -g -n`
else
CGroupUserName="$1"
CGroupGroupName="$2"
fi
echo "CGroupUserName is $CGroupUserName and CGroupGroupName is $CGroupGroupName"
cd /sys/fs/cgroup/ || exit 1
#----The top level cgroup.procs needs to be writable because the PIDs put in the lower cgroups
#----get propagated upwards
echo "chmod 666 cgroup.procs"
chmod 666 cgroup.procs || exit 1
#----Add the control groups so the lower group can too
echo "echo '+memory +cpu +cpuset' >> cgroup.subtree_control"
echo '+memory +cpu +cpuset' >> cgroup.subtree_control || exit 1
#----Make the cgroup
echo "mkdir $CGroupUserName"
mkdir "$CGroupUserName" || exit 1
#----Add the control groups
echo "echo '+memory +cpu +cpuset' >> $CGroupUserName/cgroup.subtree_control"
echo '+memory +cpu +cpuset' >> $CGroupUserName/cgroup.subtree_control || exit 1
#----Make user own it all
echo "chown -R ${CGroupUserName}:${CGroupGroupName} $CGroupUserName"
chown -R "${CGroupUserName}:${CGroupGroupName}" $CGroupUserName || exit 1