add cgroups memory task
This is important if we want Nomad to regulate and limit the amount of memory that jobs use.
This commit is contained in:
parent
0514c6fb67
commit
61463167dd
1 changed files with 39 additions and 0 deletions
39
src/steps-preinstall/50-cgroups-memory.sh
Executable file
39
src/steps-preinstall/50-cgroups-memory.sh
Executable file
|
@ -0,0 +1,39 @@
|
||||||
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
|
check_cgroups_memory() {
|
||||||
|
task_begin "Checking memory cgroups";
|
||||||
|
|
||||||
|
cgroups_enabled="$(awk '/memory/ { print $2 }' < /proc/cgroups)";
|
||||||
|
|
||||||
|
if [[ "${cgroups_enabled}" -ne 0 ]]; then
|
||||||
|
echo ">>> memory cgroups already enabled";
|
||||||
|
return 0;
|
||||||
|
fi
|
||||||
|
|
||||||
|
|
||||||
|
filepath_cmdline="/boot/cmdline.txt";
|
||||||
|
if [[ ! -e "${filepath_cmdline}" ]]; then
|
||||||
|
filepath_cmdline="/boot/firmware/cmdline.txt";
|
||||||
|
fi
|
||||||
|
if [[ ! -e "${filepath_cmdline}" ]]; then
|
||||||
|
echo ">>> Failed to find cmdline.txt; can't check for cgroups";
|
||||||
|
return 1;
|
||||||
|
fi
|
||||||
|
|
||||||
|
if grep -q cgroup_enable=memory /boot/cmdline.txt; then
|
||||||
|
echo ">>> memory cgroups already present in cmdline.txt, a reboot is required to apply the update";
|
||||||
|
return 0;
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo ">>> memory cgroups not present in cmdline.txt, enabling....";
|
||||||
|
(tr -d '\n' <"${filepath_cmdline}" && echo " cgroup_enable=memory cgroup_memory=1") | sudo tee "${filepath_cmdline}.new";
|
||||||
|
|
||||||
|
sudo mv "${filepath_cmdline}" "${filepath_cmdline}.old-$(date +"%Y-%m-%d")";
|
||||||
|
sudo mv "${filepath_cmdline}.new" "${filepath_cmdline}";
|
||||||
|
|
||||||
|
echo ">>> New contents of cmdline.txt:";
|
||||||
|
cat "${filepath_cmdline}";
|
||||||
|
echo ">>> A reboot is required to apply the changes.";
|
||||||
|
|
||||||
|
task_end "$?" "Failed to check memory cgroups"
|
||||||
|
}
|
Loading…
Reference in a new issue