diff --git a/stacks/media/BOOKS.md b/stacks/media/BOOKS.md index f752491..167ee2c 100644 --- a/stacks/media/BOOKS.md +++ b/stacks/media/BOOKS.md @@ -5,7 +5,7 @@ Lives in the `media` stack. Flow: ``` prowlarr ─► chaptarr ─► qbittorrent / nzbget ─► /storage1/complete │ - ├─ ebooks ─► /storage1/complete/books-ingest ─► CWA ─► /storage1/Media/Books (Calibre lib) ─► Send-to-Kindle / OPDS + ├─ ebooks ─► /storage1/Media/Ebooks (chaptarr's copy) ─cwa-ingest.sh hardlink─► /storage1/complete/books-ingest ─► CWA ─► /storage1/Media/Books (Calibre lib) ─► Send-to-Kindle / OPDS └─ audiobooks ─► /storage1/Media/Audiobooks ─► audiobookshelf storyteller reads both libraries :ro ─► /storage1/labdata/storyteller (aligned EPUB 3 + media overlays) ``` @@ -52,8 +52,8 @@ sudo chown -R 1000:1000 /config/chaptarr /config/calibre-web-automated /config/a ## 3. Post-deploy checklist -- [ ] **chaptarr:** set the admin login on first launch. Add root folders `/ebooks` (ebook) and `/audiobooks` (audiobook). -- [ ] **chaptarr:** turn on *Unmonitor Deleted Books* (Media Management). CWA deletes files from `/ebooks` after ingest, and without this setting chaptarr will try to grab them again. +- [ ] **chaptarr:** set the admin login on first launch. Add root folders `/ebooks` (ebook) and `/audiobooks` (audiobook). These are symlinks into the `/storage1` mount; see *Hardlinks* below. +- [x] ~~**chaptarr:** turn on *Unmonitor Deleted Books*~~. This is obsolete since 2026-12-03: CWA no longer deletes chaptarr's ebooks, because chaptarr keeps its own copy in `/storage1/Media/Ebooks`. - [ ] **Prowlarr → chaptarr app sync:** in Prowlarr, go to Settings → Apps → add Chaptarr (or Readarr if Chaptarr isn't listed yet). Use `http://prowlarr:9696` and `http://chaptarr:8789`, plus the chaptarr API key. Sync, then confirm the indexers show up in chaptarr. - [ ] **Download clients in chaptarr:** add `qbittorrent:3232` with category `books`, and `nzbget:6789` with category `books`. Both write under `/downloads` on the same `/storage1/complete` mount, so no remote path mapping is needed. Check that the `books` categories exist in both clients. - [ ] **CWA:** log in as `admin` / `admin123` and change the password right away. The library path is `/calibre-library`. Drop a test EPUB into `/storage1/complete/books-ingest` and confirm it shows up in the library and leaves the ingest folder. @@ -62,6 +62,14 @@ sudo chown -R 1000:1000 /config/chaptarr /config/calibre-web-automated /config/a - [ ] **storyteller:** create an admin and point the import at `/libraries/books` and `/libraries/audiobooks`. Run one test alignment on a short book (whisper runs on CPU, so this is slow). Open the result in the Storyteller Reader app. - [ ] **uptime-kuma:** add monitors for the four new hosts. +## Hardlinks + chaptarr's ebook copy (2026-12-03) + +- Chaptarr mounts `/storage1` **once**. `chaptarr/start.sh` (the entrypoint wrapper) symlinks `/downloads`, `/audiobooks` and `/ebooks` into it. With separate bind mounts, `link()` fails with EXDEV and chaptarr silently copied every import instead, so seeding audiobooks existed twice. The container paths didn't change, so chaptarr's DB needed no migration. +- `/ebooks` → `/storage1/Media/Ebooks` is chaptarr's own ebook folder (it used to be the CWA ingest folder, which CWA empties, so chaptarr thought every ebook was missing). +- Connect → Custom Script **"CWA ingest"** (`/scripts/cwa-ingest.sh`, On Import + On Upgrade) hardlinks each newly imported ebook into `/storage1/complete/books-ingest//`. CWA deletes its link after ingest, and chaptarr's file remains. +- Existing Calibre books were backfilled by hardlinking them from `/storage1/Media/Books` into `/storage1/Media/Ebooks//` and rescanning. +- Hardlinks share content, so never edit files in `/storage1/Media/Ebooks` in place (e.g. chaptarr metadata writing). That would also change Calibre's copy of a backfilled book. + ## Notes - `STORYTELLER_SECRET_KEY` is in `stack.env` (`secrets.token_hex(64)`). If you rotate it, every Storyteller session is logged out. diff --git a/stacks/media/chaptarr/cwa-ingest.sh b/stacks/media/chaptarr/cwa-ingest.sh new file mode 100644 index 0000000..94dc3b6 --- /dev/null +++ b/stacks/media/chaptarr/cwa-ingest.sh @@ -0,0 +1,27 @@ +#!/bin/sh +# Chaptarr Connect → Custom Script ("CWA ingest"), On Import + On Upgrade. +# +# Chaptarr keeps its own ebook copy in /ebooks (= /storage1/Media/Ebooks) so it can see what +# it already has. This hands CWA a *hardlink* of each newly imported ebook through the ingest +# folder. CWA deletes its link once it has added the book to Calibre, and chaptarr's file is +# left alone. +[ "$Chaptarr_EventType" = "Download" ] || exit 0 # also covers the "Test" button + +INGEST=/storage1/complete/books-ingest + +IFS='|' +for p in $Chaptarr_AddedBookPaths $Chaptarr_BookFile_Path; do + case "$p" in + /ebooks/*) rel=${p#/ebooks/} ;; + /storage1/Media/Ebooks/*) rel=${p#/storage1/Media/Ebooks/} ;; + *) continue ;; # audiobooks etc. + esac + [ -f "$p" ] || continue + author=${rel%%/*} + dest="$INGEST/$author/$(basename "$p")" + [ -e "$dest" ] && continue # already queued (path listed twice) + mkdir -p "$INGEST/$author" + ln "$p" "$dest" 2>/dev/null || cp "$p" "$dest" + echo "cwa-ingest: queued $p" +done +exit 0 diff --git a/stacks/media/chaptarr/start.sh b/stacks/media/chaptarr/start.sh new file mode 100644 index 0000000..03a8309 --- /dev/null +++ b/stacks/media/chaptarr/start.sh @@ -0,0 +1,25 @@ +#!/bin/sh +# Chaptarr entrypoint wrapper (compose: entrypoint: /scripts/start.sh). +# +# /storage1 is mounted ONCE; /downloads, /audiobooks and /ebooks are symlinks into it. +# Separate bind mounts make link() fail with EXDEV, and chaptarr silently falls back to a +# full copy, so every seeding audiobook used to exist twice on disk. One mount → real hardlinks. +# The container paths stay the same, so nothing in chaptarr's DB had to change. +set -e + +link() { # $1 = container path, $2 = target under /storage1 + if [ -L "$1" ]; then + ln -sfn "$2" "$1" + elif [ -d "$1" ]; then + rmdir "$1" # fails loudly if something unexpected is in there + ln -s "$2" "$1" + else + ln -s "$2" "$1" + fi +} + +link /downloads /storage1/complete +link /audiobooks /storage1/Media/Audiobooks +link /ebooks /storage1/Media/Ebooks + +exec /entrypoint.sh "$@" diff --git a/stacks/media/docker-compose.yml b/stacks/media/docker-compose.yml index 2edb9fe..6d4b6c6 100644 --- a/stacks/media/docker-compose.yml +++ b/stacks/media/docker-compose.yml @@ -251,8 +251,12 @@ services: # ============================================================ BOOKS # Prowlarr -> chaptarr -> qbittorrent/nzbget (/storage1/complete). Chaptarr - # imports ebooks into the CWA ingest folder (CWA owns the Calibre library and - # deletes ingested files) and audiobooks straight into the ABS library. + # keeps its own ebook copy in /storage1/Media/Ebooks (so it knows what it has) + # and its Custom Script hook (chaptarr/cwa-ingest.sh) hardlinks each new ebook + # into the CWA ingest folder (CWA owns the Calibre library and deletes ingested + # files). Audiobooks go straight into the ABS library. + # /storage1 is mounted once and chaptarr/start.sh symlinks /downloads, + # /audiobooks, /ebooks into it — separate bind mounts break hardlinks (EXDEV). # Storyteller reads both libraries read-only and writes aligned EPUBs to its # own /data. Readarr is retired upstream — do not add it. chaptarr: @@ -266,11 +270,12 @@ services: nofile: { soft: 65536, hard: 65536 } environment: - UMASK=002 + entrypoint: ["/bin/sh", "/scripts/start.sh"] + command: ["dotnet", "/app/Chaptarr.dll", "-nobrowser", "-data=/config"] volumes: - /config/chaptarr:/config - - /storage1/complete:/downloads - - /storage1/complete/books-ingest:/ebooks - - /storage1/Media/Audiobooks:/audiobooks + - /storage1:/storage1 + - ./chaptarr:/scripts:ro ports: - "8789:8789"