Skip to content

Instantly share code, notes, and snippets.

@hcharbonnier
Last active December 7, 2024 15:03
Show Gist options
  • Save hcharbonnier/8ce5e9ec104901d3e27f78e3ccd3fc7b to your computer and use it in GitHub Desktop.
Save hcharbonnier/8ce5e9ec104901d3e27f78e3ccd3fc7b to your computer and use it in GitHub Desktop.
Slow down mdadm raid resync/reshape when a user is connected to Jellyfin
#!/bin/bash
# Require jq :
# sudo apt install -y jq
# Setup:
# chmod +x PATHTOSCRIPT/script.sh
# CRON example:
# * * * * * PATHTOSCRIPT/script.sh
#Server uri without trailing slash
server_uri='http://JELLYFINSERVER'
# Jellyfin APIKEY
apikey='xxxxxxxxxxx'
i=0
while [ $i -lt 4 ]
do
json_data=$(curl -s -X 'GET' "${server_uri}/Sessions?activeWithinSeconds=960&api_key=${apikey}" -H 'accept: application/json')
nb_sessions=$(echo ${json_data} |jq '. | length')
if [ "$nb_sessions" == "0" ]
then
# aucune session en cours
for file in /proc/sys/dev/raid/*speed*_max /sys/block/md*/md/*speed*_max
do
grep 200000 ${file} > /dev/null 2>&1 || echo 200000 > ${file}
done
for file in /proc/sys/dev/raid/*speed*_min /sys/block/md*/md/*speed*_min
do
grep 50000 ${file} > /dev/null 2>&1 || echo 50000 > ${file}
done
else
for file in /proc/sys/dev/raid/*speed*_max /sys/block/md*/md/*speed*_max
do
grep 3000 ${file} > /dev/null 2>&1 || echo 3000 > ${file}
done
for file in /proc/sys/dev/raid/*speed*_min /sys/block/md*/md/*speed*_min
do
grep 1000 ${file} > /dev/null 2>&1 || echo 1000 > ${file}
done
fi
i=$((i+1))
sleep 14
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment