ressource check for alpine
This commit is contained in:
parent
c6d4597dca
commit
f731b57f35
@ -20,6 +20,9 @@ color
|
|||||||
catch_errors
|
catch_errors
|
||||||
|
|
||||||
function update_script() {
|
function update_script() {
|
||||||
|
header_info
|
||||||
|
check_container_storage
|
||||||
|
check_container_resources
|
||||||
UPD=$(whiptail --backtitle "Proxmox VE Helper Scripts" --title "SUPPORT" --radiolist --cancel-button Exit-Script "Spacebar = Select" 11 58 1 \
|
UPD=$(whiptail --backtitle "Proxmox VE Helper Scripts" --title "SUPPORT" --radiolist --cancel-button Exit-Script "Spacebar = Select" 11 58 1 \
|
||||||
"1" "Check for Alpine Updates" ON \
|
"1" "Check for Alpine Updates" ON \
|
||||||
3>&1 1>&2 2>&3)
|
3>&1 1>&2 2>&3)
|
||||||
|
@ -2193,41 +2193,68 @@ install_script() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
check_container_resources() {
|
check_container_resources() {
|
||||||
# Check actual RAM & Cores
|
# Determine current RAM in MB (Debian uses free, Alpine reads from /proc/meminfo)
|
||||||
current_ram=$(free -m | awk 'NR==2{print $2}')
|
if command -v free >/dev/null 2>&1; then
|
||||||
current_cpu=$(nproc)
|
current_ram=$(free -m | awk '/^Mem:/{print $2}')
|
||||||
|
elif [ -f /proc/meminfo ]; then
|
||||||
|
current_ram=$(awk '/MemTotal/{printf "%.0f", $2 / 1024}' /proc/meminfo)
|
||||||
|
else
|
||||||
|
echo "${CROSS}${HOLD} Unable to determine RAM on this system.${CL}"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
# Check whether the current RAM is less than the required RAM or the CPU cores are less than required
|
# Determine number of CPU cores (POSIX-safe)
|
||||||
if [[ "$current_ram" -lt "$var_ram" ]] || [[ "$current_cpu" -lt "$var_cpu" ]]; then
|
if command -v nproc >/dev/null 2>&1; then
|
||||||
|
current_cpu=$(nproc)
|
||||||
|
else
|
||||||
|
current_cpu=$(grep -c ^processor /proc/cpuinfo)
|
||||||
|
fi
|
||||||
|
# Check if RAM or CPU is below requirement
|
||||||
|
if [ "$current_ram" -lt "$var_ram" ] || [ "$current_cpu" -lt "$var_cpu" ]; then
|
||||||
echo -e "\n${INFO}${HOLD} ${GN}Required: ${var_cpu} CPU, ${var_ram}MB RAM ${CL}| ${RD}Current: ${current_cpu} CPU, ${current_ram}MB RAM${CL}"
|
echo -e "\n${INFO}${HOLD} ${GN}Required: ${var_cpu} CPU, ${var_ram}MB RAM ${CL}| ${RD}Current: ${current_cpu} CPU, ${current_ram}MB RAM${CL}"
|
||||||
echo -e "${YWB}Please ensure that the ${APP} LXC is configured with at least ${var_cpu} vCPU and ${var_ram} MB RAM for the build process.${CL}\n"
|
echo -e "${YWB}Please ensure that the ${APP} LXC is configured with at least ${var_cpu} vCPU and ${var_ram} MB RAM for the build process.${CL}\n"
|
||||||
echo -ne "${INFO}${HOLD} May cause data loss! ${INFO} Continue update with under-provisioned LXC? <yes/No> "
|
echo -ne "${INFO}${HOLD} May cause data loss! ${INFO} Continue update with under-provisioned LXC? <yes/No> "
|
||||||
read -r prompt
|
read -r prompt
|
||||||
# Check if the input is 'yes', otherwise exit with status 1
|
|
||||||
if [[ ! ${prompt,,} =~ ^(yes)$ ]]; then
|
case "$(printf "%s" "$prompt" | tr '[:upper:]' '[:lower:]')" in
|
||||||
|
yes) ;;
|
||||||
|
*)
|
||||||
echo -e "${CROSS}${HOLD} ${YWB}Exiting based on user input.${CL}"
|
echo -e "${CROSS}${HOLD} ${YWB}Exiting based on user input.${CL}"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
;;
|
||||||
|
esac
|
||||||
else
|
else
|
||||||
echo -e ""
|
echo -e ""
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
check_container_storage() {
|
check_container_storage() {
|
||||||
# Check if the /boot partition is more than 80% full
|
# Check if /boot is mounted and retrieve total and used blocks
|
||||||
total_size=$(df /boot --output=size | tail -n 1)
|
if df /boot >/dev/null 2>&1; then
|
||||||
local used_size=$(df /boot --output=used | tail -n 1)
|
total_size=$(df /boot | awk 'NR==2 {print $2}')
|
||||||
|
used_size=$(df /boot | awk 'NR==2 {print $3}')
|
||||||
|
else
|
||||||
|
echo -e "${CROSS}${HOLD} ${RD}/boot partition not found or cannot be checked.${CL}"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
# Fallback in case of invalid data
|
||||||
|
if [ -z "$total_size" ] || [ -z "$used_size" ]; then
|
||||||
|
echo -e "${CROSS}${HOLD} ${RD}Unable to determine storage usage.${CL}"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
# Calculate disk usage percentage (integer)
|
||||||
usage=$((100 * used_size / total_size))
|
usage=$((100 * used_size / total_size))
|
||||||
if ((usage > 80)); then
|
if [ "$usage" -gt 80 ]; then
|
||||||
# Prompt the user for confirmation to continue
|
echo -e "${INFO}${HOLD} ${YWB}Warning: /boot storage is critically low (${usage}%).${CL}"
|
||||||
echo -e "${INFO}${HOLD} ${YWB}Warning: Storage is dangerously low (${usage}%).${CL}"
|
|
||||||
echo -ne "Continue anyway? <y/N> "
|
echo -ne "Continue anyway? <y/N> "
|
||||||
read -r prompt
|
read -r prompt
|
||||||
# Check if the input is 'y' or 'yes', otherwise exit with status 1
|
case "$(printf "%s" "$prompt" | tr '[:upper:]' '[:lower:]')" in
|
||||||
if [[ ! ${prompt,,} =~ ^(y|yes)$ ]]; then
|
y | yes) ;;
|
||||||
|
*)
|
||||||
echo -e "${CROSS}${HOLD}${YWB}Exiting based on user input.${CL}"
|
echo -e "${CROSS}${HOLD}${YWB}Exiting based on user input.${CL}"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
;;
|
||||||
|
esac
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user