Files
StateGrid/install_shell/cgroup-d5000-install/set_libcgroup.sh
Mu Xiaokang 7767386657 Update cgroup-d5000-install/set_libcgroup.sh.
modified:   install_shell/cgroup-d5000-install/set_libcgroup.sh
2014-05-12 11:46:07 +08:00

100 lines
2.0 KiB
Bash
Executable File

#!/bin/sh
if [ -z $1 ];then
echo "Usage: ./set_libcgroup.sh <username>"
exit 1
fi
#设置cgconfig和cgred服务的配置文件
total_mem=`free -m | grep -i "mem" | awk '{print $2}'`
total_swap=`free -m | grep -i "swap" | awk '{print $2}'`
cpus=`cat /proc/cpuinfo | grep processor | wc -l`
((cpus=cpus-2))
if [ ${cpus} -lt 0 ]; then
cpus=0
fi
numa=`numactl --show`
if [ $? -eq 0 ]; then
# memory_nodes=`numactl --hardware | sed -n '1p' | awk '{print $2}'`
memory_nodes=`numactl --hardware | grep "nodes" | awk '{print $4}' | sed -e "s/(//g" | sed -e "s/)//g"`
else
memory_nodes=0
fi
#if [ ${memory_nodes} -ne 0 ]; then
# ((memory_nodes--))
#fi
echo "Starting set the cgconfig.conf..."
cgconfig="group $1_limits {
perm {
task {
uid = $1;
gid = $1;
}
admin {
uid = sysadmin;
gid = sysadmin;
}
}
cpuset {
cpuset.cpus = 0-var_cpus;
cpuset.mems = var_nodes;
}
memory {
memory.limit_in_bytes = var_memM;
memory.memsw.limit_in_bytes = var_swapM;
}
cpu {
cpu.rt_runtime_us = 950000;
}
}
mount {
cpuset = /lxcg;
cpu = /lxcg;
cpuacct = /lxcg;
memory = /lxcg;
devices = /lxcg;
freezer = /lxcg;
net_cls = /lxcg;
}"
cgrules="$1: * /$1_limits"
if [ ${total_mem} -le 500 ]; then
mem_root=100
else
mem_root=$((${total_mem}/10))
if [ ${mem_root} -lt 100 ]; then
mem_root=100
elif [ ${mem_root} -ge 100 ] && [ ${mem_root} -le 500 ]; then
mem_root=500
elif [ ${mem_root} -gt 2000 ]; then
mem_root=2000
fi
fi
mem=$((${total_mem}-${mem_root}))
swap=$((${total_swap}/2))
sed -i "/^[^#]/d" /etc/cgconfig.conf
sed -i "/^$/d" /etc/cgconfig.conf
echo "$cgconfig" >> /etc/cgconfig.conf
sed -i "s/var_cpus/${cpus}/g" /etc/cgconfig.conf
sed -i "s/var_nodes/${memory_nodes}/g" /etc/cgconfig.conf
sed -i "s/var_mem/${mem}/g" /etc/cgconfig.conf
sed -i "s/var_swap/$(($mem+$swap))/g" /etc/cgconfig.conf
echo "Starting set cgrules.conf..."
sed -i "/^[^#]/d" /etc/cgrules.conf
sed -i "/^$/d" /etc/cgrules.conf
echo "$cgrules" >> /etc/cgrules.conf