Skip to content
View in the app

A better way to browse. Learn more.

Unraid

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

[Script] Automatischer Neustart abhängiger Container nach VPN-/Gluetun-Restart

Featured Replies

Hallo zusammen,


sicherlich kennen einige von euch das Problem: Wenn man Docker-Container über das Netzwerk eines VPN-Containers (wie z. B. Gluetun via --net=container:gluetun) routet, verlieren die abhängigen Container die Verbindung oder stürzen ab, sobald der VPN-Container neu gestartet wird (z. B. durch ein Update oder manuellen Neustart).

Damit man die abhängigen Container nicht jedes Mal manuell neu starten muss, habe ich ein kleines Bash-Script geschrieben. Es lauscht über docker events auf den Start des VPN-Containers, wartet kurz und startet alle verknüpften Container automatisch neu. Sollte sich durch ein Update die Container-ID/der Network-Namespace geändert haben und ein Start fehlschlagen, wird direkt eine Unraid-Systembenachrichtigung (Alert) ausgelöst.

Das Script lässt sich bequem über das Plugin User Scripts einbinden (Einstellung: At Startup of Array oder als Hintergrundtask im Script).

Viel Spass damit!


#!/bin/bash

# Name des VPN-Containers
VPN_CONTAINER="gluetun"


# Abhängige Container hier eintragen

DEPENDENT_CONTAINERS=(

"qbittorrent"

# "sabnzbd"

)


echo "$(date): Docker Watcher aktiv. Überwache Container: $VPN_CONTAINER"

docker events --filter "container=$VPN_CONTAINER" --filter "event=start" | while read event; do

echo "$(date): $VPN_CONTAINER gestartet. Warte 3 Sekunden auf VPN-Tunnel..."

sleep 3

for container in "${DEPENDENT_CONTAINERS[@]}"; do

echo "$(date): Stoppe $container..."

docker stop "$container" 2>/dev/null

echo "$(date): Starte $container neu..."

# Ausgabe abfangen, um Fehler zu erkennen

START_OUTPUT=$(docker start "$container" 2>&1)

# Prüfen, ob der Namespace-Fehler (neue ID) aufgetreten ist

if [[ "$START_OUTPUT" == *"No such container"* ]] && [[ "$START_OUTPUT" == *"network namespace"* ]]; then

echo "$(date): FEHLER! Die ID von $VPN_CONTAINER hat sich geändert. $container startet nicht."

# Sendet eine rote Warn-Benachrichtigung in das Unraid Web-Interface

/usr/local/emhttp/webGui/scripts/notify -e "Docker Watcher" -s "Netzwerk-Fehler bei $container" -d "Der VPN Container hat eine neue ID bekommen (Update/Bearbeitung). Bitte bearbeite $container in Unraid und klicke auf FERTIG." -i "alert"

elif [[ -n "$START_OUTPUT" && "$START_OUTPUT" != "$container" ]]; then


# Andere unerwartete Fehler loggen

echo "$(date): Unerwarteter Fehler: $START_OUTPUT"

else

echo "$(date): $container erfolgreich neu gestartet."

fi

done

done

Edited by guybrush2012

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

Account

Navigation

Search

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.