58 lines
1.2 KiB
Bash
58 lines
1.2 KiB
Bash
#!/usr/bin/env bash
|
|
|
|
set_std_mode() {
|
|
if [[ "${VERBOSE:-no}" == "yes" ]]; then
|
|
export STD=""
|
|
else
|
|
export STD="&>/dev/null"
|
|
fi
|
|
}
|
|
|
|
get_lxc_ip() {
|
|
local interface="${1:-eth0}"
|
|
local ip=""
|
|
local counter=0
|
|
while [ -z "$ip" ] && [ $counter -lt 10 ]; do
|
|
ip=$(ip -4 addr show "$interface" | grep -oP '(?<=inet\s)\d+(\.\d+){3}' | head -n1)
|
|
if [ -z "$ip" ]; then
|
|
sleep 1
|
|
((counter++))
|
|
fi
|
|
done
|
|
echo "$ip"
|
|
}
|
|
|
|
apt_update_safe() {
|
|
msg_info "Refreshing Repositories"
|
|
local count=0
|
|
local max=3
|
|
while [ $count -lt $max ]; do
|
|
if apt-get update $STD; then
|
|
msg_ok "Repositories Refreshed"
|
|
return 0
|
|
fi
|
|
((count++))
|
|
sleep 2
|
|
done
|
|
msg_error "Repository Refresh Failed"
|
|
return 1
|
|
}
|
|
|
|
check_container_resources() {
|
|
local req_ram="${var_ram:-512}"
|
|
local req_cpu="${var_cpu:-1}"
|
|
local cur_ram=$(free -m | awk '/Mem:/ {print $2}')
|
|
local cur_cpu=$(nproc)
|
|
|
|
if [[ $cur_ram -lt $req_ram ]] || [[ $cur_cpu -lt $req_cpu ]]; then
|
|
msg_warn "Under-provisioned: System may be unstable."
|
|
fi
|
|
}
|
|
|
|
check_container_storage() {
|
|
local usage=$(df / | awk 'NR==2 {print $5}' | sed 's/%//')
|
|
if [ "$usage" -gt 90 ]; then
|
|
msg_error "Storage critical: ${usage}% utilized."
|
|
exit 1
|
|
fi
|
|
} |