|
|
|
|
@@ -5,9 +5,9 @@
|
|
|
|
|
# Synapse: https://git.techniverse.net/scriptos/livekit-ip-watch.git
|
|
|
|
|
# Autor: Patrick Asmus
|
|
|
|
|
# Web: https://www.cleveradmin.de
|
|
|
|
|
# Version: 1.0
|
|
|
|
|
# Version: 1.2.1
|
|
|
|
|
# Datum: 27.10.2025
|
|
|
|
|
# Modifikation: Initial
|
|
|
|
|
# Modifikation: Funktion "detect_compose_cmd" nachträglich committed.
|
|
|
|
|
#####################################################
|
|
|
|
|
|
|
|
|
|
set -euo pipefail
|
|
|
|
|
@@ -35,9 +35,8 @@ ENABLE_IPV6=false
|
|
|
|
|
# Wartezeit nach Neustart (Sekunden), dann Healthcheck
|
|
|
|
|
WAIT_AFTER_RESTART=20
|
|
|
|
|
|
|
|
|
|
# Healthcheck-Konfiguration: nur TCP
|
|
|
|
|
TCP_HOST="127.0.0.1"
|
|
|
|
|
TCP_PORT="7881"
|
|
|
|
|
# Healthcheck-Konfiguration: HTTP
|
|
|
|
|
HEALTHCHECK_DOMAIN="rtc.matrix.techniverse.net"
|
|
|
|
|
HEALTHCHECK_TIMEOUT=3
|
|
|
|
|
|
|
|
|
|
# ntfy (optional)
|
|
|
|
|
@@ -125,13 +124,25 @@ backup_config() {
|
|
|
|
|
echo "$backup"
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
is_mikefarah_yq() {
|
|
|
|
|
yq --version 2>&1 | grep -qi 'mikefarah'
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
update_yaml_with_yq() {
|
|
|
|
|
local cidr="$1"
|
|
|
|
|
YQ_VAR_CIDR="$cidr" yq -i '
|
|
|
|
|
.rtc |= (. // {}) |
|
|
|
|
|
.rtc.ips |= (. // {}) |
|
|
|
|
|
.rtc.ips.includes = [env(YQ_VAR_CIDR)]
|
|
|
|
|
if is_mikefarah_yq; then
|
|
|
|
|
CIDR="$cidr" yq eval -i '
|
|
|
|
|
.rtc = (.rtc // {}) |
|
|
|
|
|
.rtc.ips = (.rtc.ips // {}) |
|
|
|
|
|
.rtc.ips.includes = [env(CIDR)]
|
|
|
|
|
' "$CONFIG_FILE"
|
|
|
|
|
else
|
|
|
|
|
yq -y -i --arg CIDR "$cidr" '
|
|
|
|
|
.rtc = (.rtc // {}) |
|
|
|
|
|
.rtc.ips = (.rtc.ips // {}) |
|
|
|
|
|
.rtc.ips.includes = [$CIDR]
|
|
|
|
|
' "$CONFIG_FILE"
|
|
|
|
|
fi
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
update_yaml_fallback() {
|
|
|
|
|
@@ -139,35 +150,55 @@ update_yaml_fallback() {
|
|
|
|
|
local tmp
|
|
|
|
|
tmp="$(mktemp)"
|
|
|
|
|
awk -v newcidr="$cidr" '
|
|
|
|
|
BEGIN{ in_rtc=0; in_ips=0; in_includes=0; injected=0 }
|
|
|
|
|
function indent_of(s, m,sp) { match(s,/^([ ]*)/,m); sp=length(m[1]); return sp }
|
|
|
|
|
BEGIN { in_rtc=0; rtc_indent=-1; skipping_ips=0; ips_indent=-1; injected=0 }
|
|
|
|
|
{
|
|
|
|
|
line=$0
|
|
|
|
|
if ($0 ~ /^[[:space:]]*rtc:[[:space:]]*$/) { in_rtc=1; in_ips=0; in_includes=0 }
|
|
|
|
|
else if (in_rtc && $0 ~ /^[[:space:]]*[[:alnum:]_]+:[[:space:]]*$/ && $0 !~ /^[[:space:]]*ips:/) {
|
|
|
|
|
if (!in_ips && !in_includes && !injected) {
|
|
|
|
|
ind=indent_of(line)
|
|
|
|
|
|
|
|
|
|
if ($0 ~ /^[[:space:]]*rtc:[[:space:]]*$/) {
|
|
|
|
|
in_rtc=1; rtc_indent=ind; injected=0
|
|
|
|
|
print line
|
|
|
|
|
next
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (in_rtc) {
|
|
|
|
|
if (skipping_ips) {
|
|
|
|
|
if (ind <= ips_indent) {
|
|
|
|
|
if (!injected) {
|
|
|
|
|
print " ips:"
|
|
|
|
|
print " includes:"
|
|
|
|
|
print " - " newcidr
|
|
|
|
|
injected=1
|
|
|
|
|
}
|
|
|
|
|
skipping_ips=0
|
|
|
|
|
} else { next }
|
|
|
|
|
}
|
|
|
|
|
if (in_rtc && $0 ~ /^[[:space:]]*ips:[[:space:]]*$/) { in_ips=1; in_includes=0 }
|
|
|
|
|
if (in_ips && $0 ~ /^[[:space:]]*includes:[[:space:]]*$/) { in_includes=1; next }
|
|
|
|
|
if (in_includes) {
|
|
|
|
|
if ($0 ~ /^[[:space:]]*-[[:space:]]*[^[:space:]]+/) {
|
|
|
|
|
|
|
|
|
|
if ($0 ~ /^[[:space:]]*ips:[[:space:]]*$/ && ind > rtc_indent) {
|
|
|
|
|
skipping_ips=1; ips_indent=ind
|
|
|
|
|
next
|
|
|
|
|
} else {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (ind <= rtc_indent && $0 ~ /^[[:alnum:]]_+:[[:space:]]*$/) {
|
|
|
|
|
if (!injected) {
|
|
|
|
|
print " ips:"
|
|
|
|
|
print " includes:"
|
|
|
|
|
print " - " newcidr
|
|
|
|
|
injected=1
|
|
|
|
|
}
|
|
|
|
|
in_includes=0
|
|
|
|
|
in_ips=($0 ~ /^[[:space:]]*ips:/)?1:0
|
|
|
|
|
in_rtc=0; rtc_indent=-1
|
|
|
|
|
print line
|
|
|
|
|
next
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
print line
|
|
|
|
|
next
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
print line
|
|
|
|
|
}
|
|
|
|
|
END{
|
|
|
|
|
END {
|
|
|
|
|
if (in_rtc && !injected) {
|
|
|
|
|
print " ips:"
|
|
|
|
|
print " includes:"
|
|
|
|
|
@@ -199,16 +230,9 @@ restart_service() {
|
|
|
|
|
fi
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
healthcheck_tcp() {
|
|
|
|
|
if (exec 3<>/dev/tcp/"$TCP_HOST"/"$TCP_PORT") 2>/dev/null; then
|
|
|
|
|
exec 3<&-
|
|
|
|
|
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
|
|
|
|
|
healthcheck_http() {
|
|
|
|
|
local url="https://${HEALTHCHECK_DOMAIN}/livekit/sfu/"
|
|
|
|
|
curl -fsS --max-time "$HEALTHCHECK_TIMEOUT" "$url" >/dev/null
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
main() {
|
|
|
|
|
@@ -263,7 +287,7 @@ main() {
|
|
|
|
|
info "Warte $WAIT_AFTER_RESTART Sekunden..."
|
|
|
|
|
sleep "$WAIT_AFTER_RESTART"
|
|
|
|
|
|
|
|
|
|
if healthcheck_tcp; then
|
|
|
|
|
if healthcheck_http; then
|
|
|
|
|
info "Healthcheck OK."
|
|
|
|
|
echo "$current_ip" > "$state_file"
|
|
|
|
|
notify "info" "IP geändert auf $current_ip, Dienst gesund."
|
|
|
|
|
@@ -280,7 +304,7 @@ main() {
|
|
|
|
|
info "Warte $WAIT_AFTER_RESTART Sekunden (Rollback)..."
|
|
|
|
|
sleep "$WAIT_AFTER_RESTART"
|
|
|
|
|
|
|
|
|
|
if healthcheck_tcp; then
|
|
|
|
|
if healthcheck_http; then
|
|
|
|
|
warn "Rollback erfolgreich. System läuft wieder mit alter Konfiguration."
|
|
|
|
|
notify "warn" "Rollback erfolgreich. Bitte prüfen. Alte IP bleibt ${last_ip:-unbekannt}."
|
|
|
|
|
exit 10
|
|
|
|
|
|