Openai/69236e64-afe0-8013-9002-2bf25d4615fd

Revision as of 06:34, 24 November 2025 by Lukegao (talk | contribs) (by freem.ai...)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)


This conversation was exported from ChatGPT[1]

gpt-5-1 edit

User: Restart container when another is rebooted/upgraded edit

Restart container when another is rebooted/upgraded

Hi

Can anyone tell me how to automatically have a container restart when another go down

I have qbitorrent and Qbit-guard, issue is whenever qbit is rebooted the guard goes down and i dont always realise its offline and i would like to automate it is possible

Assistant: You’ve got a couple clean ways to solve this depending on where you’re running the containers Docker, Docker Compose, P… edit

You’ve got a couple clean ways to solve this depending on where you’re running the containers (Docker, Docker Compose, Portainer, Unraid, Proxmox LXC running Docker inside, etc.). I’ll walk you through the practical options so you can pick what fits.

✅ If you’re using Docker Compose edit

This is the best solution because Docker already supports dependency ordering.

Add this to qbit-guard:

depends_on:
  qbittorrent:
    condition: service_healthy

…AND make sure qbittorrent has a healthcheck:

services:
  qbittorrent:
    image: linuxserver/qbittorrent
    healthcheck:
      test: ["CMD", "curl", "-f", "http://localhost:8080"]
      interval: 30s
      timeout: 5s
      retries: 5

Then:

qbit-guard:
  depends_on:
    qbittorrent:
      condition: service_healthy
  restart: always

Effect:

  • If qbittorrent restarts → qbit-guard automatically gets restarted once qbit is up and healthy.

✅ If you’re using plain Docker (no compose) edit

You need a watchdog container or a small script. Easiest option:

Script approach: edit
#!/bin/bash

while true; do
    if [ "$(docker inspect -f '{{.State.Status}}' qbittorrent)" != "running" ]; then
        docker restart qbit-guard
    fi
    sleep 10
done

Run it as a small systemd service or container.

✅ If you’re running on Unraid edit

Unraid can do this:

  1. Go to Docker tab
  2. Click on qbit-guard
  3. Set "Wait for other containers" (if using Docker Compose plugin, see above)

Or install CA User Scripts plugin:

Script:

if [ "$(docker inspect -f '{{.State.Status}}' qbittorrent)" = "running" ]; then
    exit 0
else
    docker restart qbit-guard
fi

Schedule: run every 5 minutes.

⚠️ If you’re running LXC containers directly in Proxmox edit

Then you’re not using Docker at all.

In that case you need:

Option A: Use a hookscript edit

Proxmox supports hooks that run on container start/stop.

Example /root/restart-guard.pm:

#!/usr/bin/perl

use strict;
use warnings;

my $vmid = shift;
my $phase = shift;

if ($vmid == 101 && $phase eq 'post-stop') {
    system("pct restart 102");
}
  • 101 = qbittorrent LXC
  • 102 = qbit-guard LXC

Then assign the hookscript:

pct set 101 -hookscript /root/restart-guard.pm
Option B: Don’t run them as LXCs — run them both inside a single Docker host edit

Honestly this is the cleaner long-term path.

👉 Tell me what environment you’re actually running this on (Docker? Docker Compose? Unraid? Proxmox LXCs?) and I’ll give you the exact config. edit

I can generate the exact compose file, systemd service, or Proxmox hook for your setup.

References edit

  1. "Container restart automation". ChatGPT. Retrieved 2025-11-24.