Add availability checker for remote services based on ping and timeout

This commit is contained in:
Gergely Koloszar 2025-10-16 20:50:42 +02:00
parent 936dfe8d02
commit f0657be289

View File

@ -493,6 +493,22 @@ stale_symlinks(){
unlink "$l"
done
}
check_availability() {
if [[ -z $1 ]]; then
return 1
fi
local url=$1
local timeout_sec="3"
if [[ $2 ]]; then
timeout_sec=$2
fi
if ! ping -w "$timeout_sec" "$url"; then
logger WARN "Failed to reach $url, service may be down."
return 1
fi
}
local_latlon(){
if [[ -z $(command -v dig) ]]; then
local local_ip=$(curl -Ls "https://ipecho.net/plain")