Last active
December 7, 2024 15:03
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/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