Skip to content

Instantly share code, notes, and snippets.

@martin-juul
Last active September 24, 2020 19:47
Show Gist options
  • Save martin-juul/8d2b3deb0ffef48f74e780d0e656a270 to your computer and use it in GitHub Desktop.
Save martin-juul/8d2b3deb0ffef48f74e780d0e656a270 to your computer and use it in GitHub Desktop.
Script for constraining containers on media box. This one is used on a 6c/12t CPU - adjust to your needs.
#!/bin/bash
errexit() {
local err=$?
set +o xtrace
local code="${1:-1}"
echo "Error in ${BASH_SOURCE[1]}:${BASH_LINENO[0]}. '${BASH_COMMAND}' exited with status $err"
# Print out the stack trace described by $function_stack
if [ ${#FUNCNAME[@]} -gt 2 ]
then
echo "Call tree:"
for ((i=1;i<${#FUNCNAME[@]}-1;i++))
do
echo " $i: ${BASH_SOURCE[$i+1]}:${BASH_LINENO[$i]} ${FUNCNAME[$i]}(...)"
done
fi
echo "Exiting with status ${code}"
exit "${code}"
}
trap 'errexit' ERR
set -o errtrace
docker update --memory "8gb" --cpuset-cpus=2,6 plex || true
declare -a low_pri_containers=("nzbget" "jackett" "sonarr" "radarr" "rutorrent" "postgres12" "wikijs-db" "wikijs_blockdiag_1" "wikijs_kroki_1" "wikijs_mermaid_1" "wikijs_wiki_1")
for container in "${low_pri_containers[@]}"; do
echo "[lowpri]: restricting $container"
docker update "$container" --memory "2gb" --cpus=2 --cpuset-cpus=7,11 || true
done
@martin-juul
Copy link
Author

Pleaase don't allocate cpu0 if you use this. The schedulers like to use it for network.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment