yamlfix #1
@ -5,9 +5,9 @@
|
|||||||
# Synapse: https://git.techniverse.net/scriptos/livekit-ip-watch.git
|
# Synapse: https://git.techniverse.net/scriptos/livekit-ip-watch.git
|
||||||
# Autor: Patrick Asmus
|
# Autor: Patrick Asmus
|
||||||
# Web: https://www.cleveradmin.de
|
# Web: https://www.cleveradmin.de
|
||||||
# Version: 1.0
|
# Version: 1.1
|
||||||
# Datum: 27.10.2025
|
# Datum: 27.10.2025
|
||||||
# Modifikation: Initial
|
# Modifikation: healthcheck auf HTTP mit Custom URL umgestellt.
|
||||||
#####################################################
|
#####################################################
|
||||||
|
|
||||||
set -euo pipefail
|
set -euo pipefail
|
||||||
@ -35,9 +35,8 @@ ENABLE_IPV6=false
|
|||||||
# Wartezeit nach Neustart (Sekunden), dann Healthcheck
|
# Wartezeit nach Neustart (Sekunden), dann Healthcheck
|
||||||
WAIT_AFTER_RESTART=20
|
WAIT_AFTER_RESTART=20
|
||||||
|
|
||||||
# Healthcheck-Konfiguration: nur TCP
|
# Healthcheck-Konfiguration: HTTP
|
||||||
TCP_HOST="127.0.0.1"
|
HEALTHCHECK_DOMAIN="rtc.matrix.techniverse.net"
|
||||||
TCP_PORT="7881"
|
|
||||||
HEALTHCHECK_TIMEOUT=3
|
HEALTHCHECK_TIMEOUT=3
|
||||||
|
|
||||||
# ntfy (optional)
|
# ntfy (optional)
|
||||||
@ -139,45 +138,36 @@ update_yaml_fallback() {
|
|||||||
local tmp
|
local tmp
|
||||||
tmp="$(mktemp)"
|
tmp="$(mktemp)"
|
||||||
awk -v newcidr="$cidr" '
|
awk -v newcidr="$cidr" '
|
||||||
BEGIN{ in_rtc=0; in_ips=0; ips_indent=""; printed_ips=0 }
|
BEGIN{ in_rtc=0; in_ips=0; in_includes=0; injected=0 }
|
||||||
function print_ips_block() {
|
|
||||||
if (!printed_ips) {
|
|
||||||
print " ips:"
|
|
||||||
print " includes:"
|
|
||||||
print " - " newcidr
|
|
||||||
printed_ips=1
|
|
||||||
}
|
|
||||||
}
|
|
||||||
{
|
{
|
||||||
line=$0
|
line=$0
|
||||||
if ($0 ~ /^[[:space:]]*rtc:[[:space:]]*$/) { in_rtc=1; in_ips=0; ips_indent=""; print; next }
|
if ($0 ~ /^[[:space:]]*rtc:[[:space:]]*$/) { in_rtc=1; in_ips=0; in_includes=0 }
|
||||||
if (in_rtc) {
|
else if (in_rtc && $0 ~ /^[[:space:]]*[[:alnum:]_]+:[[:space:]]*$/ && $0 !~ /^[[:space:]]*ips:/) {
|
||||||
if (in_ips) {
|
if (!in_ips && !in_includes && !injected) {
|
||||||
if (ips_indent=="" ) { next }
|
print " ips:"
|
||||||
if ($0 ~ "^" ips_indent "[^[:space:]]") { next }
|
print " includes:"
|
||||||
in_ips=0
|
print " - " newcidr
|
||||||
print_ips_block()
|
injected=1
|
||||||
}
|
}
|
||||||
if ($0 ~ /^[[:space:]]{2}ips:[[:space:]]*$/) {
|
}
|
||||||
in_ips=1
|
if (in_rtc && $0 ~ /^[[:space:]]*ips:[[:space:]]*$/) { in_ips=1; in_includes=0 }
|
||||||
match($0,/^([[:space:]]*)ips:/,m)
|
if (in_ips && $0 ~ /^[[:space:]]*includes:[[:space:]]*$/) { in_includes=1; next }
|
||||||
ips_indent=m[1]" "
|
if (in_includes) {
|
||||||
|
if ($0 ~ /^[[:space:]]*-[[:space:]]*[^[:space:]]+/) {
|
||||||
next
|
next
|
||||||
|
} else {
|
||||||
|
if (!injected) {
|
||||||
|
print " - " newcidr
|
||||||
|
injected=1
|
||||||
|
}
|
||||||
|
in_includes=0
|
||||||
|
in_ips=($0 ~ /^[[:space:]]*ips:/)?1:0
|
||||||
}
|
}
|
||||||
if ($0 ~ /^[[:space:]]{2}[[:alnum:]_]+:[[:space:]]*$/) {
|
|
||||||
if (!printed_ips) { print_ips_block() }
|
|
||||||
}
|
|
||||||
if ($0 ~ /^[[:alnum:]_]+:[[:space:]]*$/) {
|
|
||||||
if (!printed_ips && in_rtc) { print_ips_block() }
|
|
||||||
in_rtc=0
|
|
||||||
}
|
|
||||||
print line
|
|
||||||
next
|
|
||||||
}
|
}
|
||||||
print line
|
print line
|
||||||
}
|
}
|
||||||
END{
|
END{
|
||||||
if (in_rtc && !printed_ips) {
|
if (in_rtc && !injected) {
|
||||||
print " ips:"
|
print " ips:"
|
||||||
print " includes:"
|
print " includes:"
|
||||||
print " - " newcidr
|
print " - " newcidr
|
||||||
@ -208,16 +198,9 @@ restart_service() {
|
|||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
healthcheck_tcp() {
|
healthcheck_http() {
|
||||||
if (exec 3<>/dev/tcp/"$TCP_HOST"/"$TCP_PORT") 2>/dev/null; then
|
local url="https://${HEALTHCHECK_DOMAIN}/livekit/sfu/"
|
||||||
exec 3<&-
|
curl -fsS --max-time "$HEALTHCHECK_TIMEOUT" "$url" >/dev/null
|
||||||
exec 3>&-
|
|
||||||
return 0
|
|
||||||
elif command -v nc >/dev/null 2>&1; then
|
|
||||||
nc -z -w "$HEALTHCHECK_TIMEOUT" "$TCP_HOST" "$TCP_PORT"
|
|
||||||
else
|
|
||||||
return 1
|
|
||||||
fi
|
|
||||||
}
|
}
|
||||||
|
|
||||||
main() {
|
main() {
|
||||||
@ -272,7 +255,7 @@ main() {
|
|||||||
info "Warte $WAIT_AFTER_RESTART Sekunden..."
|
info "Warte $WAIT_AFTER_RESTART Sekunden..."
|
||||||
sleep "$WAIT_AFTER_RESTART"
|
sleep "$WAIT_AFTER_RESTART"
|
||||||
|
|
||||||
if healthcheck_tcp; then
|
if healthcheck_http; then
|
||||||
info "Healthcheck OK."
|
info "Healthcheck OK."
|
||||||
echo "$current_ip" > "$state_file"
|
echo "$current_ip" > "$state_file"
|
||||||
notify "info" "IP geändert auf $current_ip, Dienst gesund."
|
notify "info" "IP geändert auf $current_ip, Dienst gesund."
|
||||||
@ -289,7 +272,7 @@ main() {
|
|||||||
info "Warte $WAIT_AFTER_RESTART Sekunden (Rollback)..."
|
info "Warte $WAIT_AFTER_RESTART Sekunden (Rollback)..."
|
||||||
sleep "$WAIT_AFTER_RESTART"
|
sleep "$WAIT_AFTER_RESTART"
|
||||||
|
|
||||||
if healthcheck_tcp; then
|
if healthcheck_http; then
|
||||||
warn "Rollback erfolgreich. System läuft wieder mit alter Konfiguration."
|
warn "Rollback erfolgreich. System läuft wieder mit alter Konfiguration."
|
||||||
notify "warn" "Rollback erfolgreich. Bitte prüfen. Alte IP bleibt ${last_ip:-unbekannt}."
|
notify "warn" "Rollback erfolgreich. Bitte prüfen. Alte IP bleibt ${last_ip:-unbekannt}."
|
||||||
exit 10
|
exit 10
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user