deunhealth icon indicating copy to clipboard operation
deunhealth copied to clipboard

Feature request: auto-restart containers depend on restart unhealthly parent

Open PiDroid-B opened this issue 3 years ago • 1 comments

context

When we have containers (aka childs) depending on another container (parent), the childs doesn't restart when the parent is failing and restarts.

services:
  parent_container:
      labels:
      - deunhealth.restart.on.unhealthy=true
     [...]
     
  child1:
    depends_on:
      parent_container:
        condition: service_healthy
      network_mode: "service:parent_container"
      labels:
      - deunhealth.restart.on.unhealthy=true    
     [...]        

  child2:
    depends_on:
      parent_container:
        condition: service_healthy
      network_mode: "service:parent_container"
      labels:
      - deunhealth.restart.on.unhealthy=true
     [...]        

What's the feature? 🧐

  • Add a solution to check childs when a restart of the parent is required and restart them when parent is "running" and/or "healthly".

Suggested solution

Maybe something like that :

add a label for child : deunhealth.restart.on.depends_on=true (maybe change "true" to the parent's container_name)

workflow of auto-restart parent :
     -  restart the container (parent)
     -  get list of other containers contains the according label (childs)
              - if state is not running/healthly then restart it

Thank's for your help.

PiDroid-B avatar Jun 26 '22 10:06 PiDroid-B

This would be a welcome feature, but I have noticed that sometimes the child containers are still in a health state even after the parent restarts.

An example would be using and vpn (say gluetun) and torrent client when the vpn client becomes unhealthy it restarts which the vpn client, effectively activating the kill switch on torrent container, yet it still reports as healthy.

I think the workflow should be (which would cover the edge case mention above)

if parent container is restarted, restart dependent containers regardless of state

example compose snippet

vpn:
    image: qmcgaw/gluetun:latest
    container_name: vpn
    cap_add:
      - NET_ADMIN
    devices:
      - /dev/net/tun:/dev/net/tun
    ports:
      - "${TORRENT}:${TORRENT}"
      - "${TORRENT}:${TORRENT}/udp"
      - "${TORRENT_WEB}:${TORRENT_WEB}"
    volumes:
      - config_vpn:/gluetun:rw
      - ./wg0.conf:/gluetun/wireguard/wg0.conf:ro
    environment:
      - VPN_SERVICE_PROVIDER=${VPN_SERVICE_PROVIDER}
      - VPN_TYPE=${VPN_TYPE}
      - FIREWALL_VPN_INPUT_PORTS=${TORRENT}
    restart: always

torrent:
    image: linuxserver/qbittorrent:latest
    container_name: qbittorrent
    network_mode: "service:vpn"
    environment:
      - WEBUI_PORT=${TORRENT_WEB}
      - TORRENTING_PORT=${TORRENT}
      - PORT=${TORRENT}
      - DOCKER_MODS=ghcr.io/gabe565/linuxserver-mod-vuetorrent
      - PUID=${PUID}
      - PGID=${PGID}
      - TZ=${TIMEZONE}
      - UMASK=${UMASK}
    volumes:
      - config_qbittorrent:/config:rw
      - download:/mnt/downloads:rw
    labels:
      - "depends_on=vpn"
      - "traefik.enable=true"
      - "traefik.http.routers.qbittorrent.rule=Host(`qbittorrent.${DNS_DOMAIN_SUFFIX}`)"
      - "traefik.http.routers.qbittorrent.tls=true"
      - "traefik.http.services.qbittorrent.loadbalancer.server.port=${TORRENT_WEB}"
    depends_on:
      vpn:
        condition: service_healthy
        restart: true
    restart: always
    healthcheck:
      test: ["CMD-SHELL", "pgrep qbittorrent || exit 1"]
      interval: ${INTERVAL_IN_SECS}
      retries: ${RETRIES}
      start_period: ${START_PERIOD_IN_SECS}
      timeout: ${TIMEOUT_IN_SECS}

ondrovic avatar Jan 27 '25 13:01 ondrovic