Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
PiDroid-B opened this issue Jun 26, 2022 · 1 comment

Comments

@PiDroid-B
Copy link

PiDroid-B commented Jun 26, 2022

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 PiDroid-B changed the title Feature request: auto-restart of containers contains depends_on when the parent container will be restart Feature request: auto-restart containers depend on restart unhealthly parent Jun 26, 2022
@ondrovic
Copy link

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}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants