mirror of
https://github.com/tteck/Proxmox.git
synced 2024-11-25 17:55:01 +01:00
Update scaling-governor.sh
- A full code overhaul. - Include an option to configure a crontab for ensuring that the CPU Scaling Governor configuration persists across reboots.
This commit is contained in:
parent
6aeda1d4ff
commit
2d85b461bd
@ -8,51 +8,45 @@
|
|||||||
header_info() {
|
header_info() {
|
||||||
clear
|
clear
|
||||||
cat <<EOF
|
cat <<EOF
|
||||||
__________ __ __
|
________ __ __ _____
|
||||||
/ ____/ __ \/ / / /
|
/ ___/ _ \/ / / / / ___/__ _ _____ _______ ___ _______
|
||||||
/ / / /_/ / / / /
|
/ /__/ ___/ /_/ / / (_ / _ \ |/ / -_) __/ _ \/ _ \/ __(_-<
|
||||||
/ /___/ ____/ /_/ /
|
\___/_/ \____/ \___/\___/___/\__/_/ /_//_/\___/_/ /___/
|
||||||
\____/_/ \____/
|
|
||||||
Scaling Governors
|
|
||||||
EOF
|
EOF
|
||||||
}
|
}
|
||||||
while true; do
|
|
||||||
header_info
|
header_info
|
||||||
read -p "View CPU Scaling Governors. Proceed(y/n)?" yn
|
whiptail --backtitle "Proxmox VE Helper Scripts" --title "CPU Scaling Governors" --yesno "View/Change CPU Scaling Governors. Proceed?" 10 58 || exit
|
||||||
case $yn in
|
current_governor=$(cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor)
|
||||||
[Yy]*) break ;;
|
GOVERNORS_MENU=()
|
||||||
[Nn]*) exit ;;
|
MSG_MAX_LENGTH=0
|
||||||
*) echo "Please answer yes or no." ;;
|
while read -r TAG ITEM; do
|
||||||
esac
|
OFFSET=2
|
||||||
done
|
((${#ITEM} + OFFSET > MSG_MAX_LENGTH)) && MSG_MAX_LENGTH=${#ITEM}+OFFSET
|
||||||
show_menu() {
|
GOVERNORS_MENU+=("$TAG" "$ITEM " "OFF")
|
||||||
header_info
|
done < <(cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_available_governors | tr ' ' '\n' | grep -v "$current_governor")
|
||||||
echo -e "\nProxmox IP \033[36m$(hostname -I)\033[m"
|
scaling_governor=$(whiptail --backtitle "Proxmox VE Helper Scripts" --title "Current CPU Scaling Governor is set to $current_governor" --checklist "\nSelect the Scaling Governor to use:\n" 16 $((MSG_MAX_LENGTH + 58)) 6 "${GOVERNORS_MENU[@]}" 3>&1 1>&2 2>&3 | tr -d '"') || exit
|
||||||
echo -e "Current Kernel \033[36m$(uname -r)\033[m\n"
|
echo "${scaling_governor}" | tee /sys/devices/system/cpu/cpu*/cpufreq/scaling_governor >/dev/null
|
||||||
available_governors=$(cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_available_governors)
|
current_governor=$(cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor)
|
||||||
echo -e "Available CPU Scaling Governors\n\033[36m${available_governors}\033[m\n"
|
whiptail --backtitle "Proxmox VE Helper Scripts" --msgbox --title "Current CPU Scaling Governor" "\nCurrent CPU Scaling Governor has been set to $current_governor\n" 10 60
|
||||||
echo -e "Current CPU Scaling Governor\n\033[36m$(cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor)\033[m\n"
|
CHOICE=$(whiptail --backtitle "Proxmox VE Helper Scripts" --title "CPU Scaling Governor" --menu "This will establish a crontab to maintain the CPU Scaling Governor configuration across reboots.\n \nSetup a crontab?" 14 68 2 \
|
||||||
options=""
|
"yes" " " \
|
||||||
i=1
|
"no" " " 3>&2 2>&1 1>&3)
|
||||||
for governor in $available_governors
|
|
||||||
do
|
case $CHOICE in
|
||||||
options+="** ${i}) \033[36m${governor}\033[m CPU Scaling Governor\n"
|
yes)
|
||||||
((i=i+1))
|
NEW_CRONTAB_COMMAND="(sleep 60 && echo \"$current_governor\" | tee /sys/devices/system/cpu/cpu*/cpufreq/scaling_governor)"
|
||||||
done
|
EXISTING_CRONTAB=$(crontab -l 2>/dev/null)
|
||||||
echo -e "${options}"
|
if [[ -n "$EXISTING_CRONTAB" ]]; then
|
||||||
echo -e "\033[31mNOTE: Settings return to default after reboot\033[m\n"
|
TEMP_CRONTAB_FILE=$(mktemp)
|
||||||
read -p "Please choose an option from the menu and press [ENTER] or x to exit." opt
|
echo "$EXISTING_CRONTAB" | grep -v "@reboot (sleep 60 && echo*" > "$TEMP_CRONTAB_FILE"
|
||||||
}
|
crontab "$TEMP_CRONTAB_FILE"
|
||||||
show_menu
|
rm "$TEMP_CRONTAB_FILE"
|
||||||
while [[ "$opt" != "" ]]; do
|
|
||||||
num_governors=$(echo "$available_governors" | wc -w)
|
|
||||||
if [[ $opt -gt 0 ]] && [[ $opt -le $num_governors ]]; then
|
|
||||||
governor=$(echo "$available_governors" | cut -d' ' -f $opt)
|
|
||||||
echo "${governor}" | tee /sys/devices/system/cpu/cpu*/cpufreq/scaling_governor
|
|
||||||
elif [[ $opt == "x" ]] || [[ $opt == "\n" ]]; then
|
|
||||||
exit
|
|
||||||
else
|
|
||||||
show_menu
|
|
||||||
fi
|
fi
|
||||||
show_menu
|
(crontab -l 2>/dev/null; echo "@reboot $NEW_CRONTAB_COMMAND") | crontab -
|
||||||
done
|
echo -e "\nCrontab Set (use 'crontab -e' to check)"
|
||||||
|
;;
|
||||||
|
no)
|
||||||
|
echo -e "\n\033[31mNOTE: Settings return to default after reboot\033[m\n"
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
echo -e "Current CPU Scaling Governor is set to \033[36m$current_governor\033[m\n"
|
||||||
|
Loading…
Reference in New Issue
Block a user