Skip to content

[FEAT] Add automatic recovery when Plex media mounts become unavailable or stale #459

Description

@sanchez1337

Is this a new feature request?

  • I have searched the existing issues

Wanted change

For the most part this issue has been described by GPT-5.6 Sol. I wouldn't know most of those things nearly enough to propose concise change by myself so sorry for using AI but I believe core idea is valid based on my own scenario.

Add a media-mount watchdog integrated with the image’s s6 services.

The watchdog could:

  • Monitor the documented /movies and /tv paths when they are mounted.

  • Allow custom paths through an environment variable, for example:

    environment:
      - PLEX_MEDIA_PATHS=/movies,/tv,/music
    
  • Detect persistent storage errors such as:

    • ESTALE
    • EIO
    • inaccessible or disconnected NFS/CIFS mounts
  • Use an initial grace period and several consecutive failures to avoid reacting to short interruptions.

  • Report the problem clearly in the container log and Docker health status.

  • Cleanly terminate the container when its mount namespace cannot recover, allowing the configured Docker restart policy to start it with fresh mounts.

  • Provide an option to disable the watchdog if required.

Refreshing host bind mounts from inside an unprivileged container may not be possible, so exiting cleanly and allowing Docker to restart the container would be an acceptable implementation.

Ideally, /movies and /tv would be monitored automatically when they are detected as network-backed mounts, with PLEX_MEDIA_PATHS available for additional or non-standard locations.

Reason for change

The documented /movies and /tv volumes are commonly backed by NAS storage using NFS or CIFS.

When a NAS restarts, these mounts can temporarily become unavailable or return errors such as ESTALE (Stale file handle). Plex remains running, so Docker restart policies such as unless-stopped are never triggered. Even after the host mount recovers, Plex may remain attached to stale bind mounts until the container is manually restarted or recreated.

Users currently need external watchdogs, Docker socket sidecars, systemd services, or healthchecks that terminate PID 1. It would be useful for the image to provide a supported recovery mechanism.

In my own case whenever NFS restarts I have it automatically re-mount on plex's VM, but even when it does I always have to manually recreate the container for it to get re-mounted directories.

Proposed code change

Not nearly advanced enough to propose anything.

Below something GPT-5.6 Sol came up with temporarily for my use case:

    healthcheck:
      test:
        - CMD-SHELL
        - >-
          probe() {
          probe_output=$$(timeout -k 5s 15s stat
          "$$1/.plex-healthcheck-$$(date +%s%N)-$$$$" 2>&1);
          probe_status=$$?;
          [ "$$probe_status" -eq 1 ] &&
          printf '%s\n' "$$probe_output" | grep -q 'No such file or directory';
          };
          if findmnt -rn -t nfs,nfs4 -T /movies >/dev/null 2>&1 &&
          findmnt -rn -t nfs,nfs4 -T /tv >/dev/null 2>&1 &&
          probe /movies && probe /tv; then
          rm -f /tmp/plex-media-health-failures;
          exit 0;
          fi;
          failures=0;
          read -r failures < /tmp/plex-media-health-failures 2>/dev/null || true;
          case "$$failures" in ''|*[!0-9]*) failures=0;; esac;
          failures=$$((failures + 1));
          printf '%s\n' "$$failures" > /tmp/plex-media-health-failures;
          if [ "$$failures" -ge 3 ]; then
          echo "Media mounts failed three consecutive checks; restarting Plex" >&2;
          rm -f /tmp/plex-media-health-failures;
          kill -TERM 1;
          fi;
          exit 1
      interval: 30s
      timeout: 25s
      start_period: 90s
      retries: 3
    restart: unless-stopped

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    Status
    Done

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions