Files
homelabstack/stacks/media/BOOKS.md
T
ginnoir (outpost agent)andClaude Opus 5.5 5d70a4e825 feat(media): chaptarr hardlinks + keeps its own ebook copy
Chaptarr had /downloads, /ebooks and /audiobooks as separate bind mounts, so
hardlinks failed with EXDEV and every import was a full copy (each seeding
audiobook stored twice). Mount /storage1 once and symlink the old container
paths into it via an entrypoint wrapper, so nothing in chaptarr's DB changes.

/ebooks now points at /storage1/Media/Ebooks, chaptarr's own ebook folder.
A Custom Script hook hardlinks each new ebook into the CWA ingest folder, so
CWA deleting its ingest copy no longer makes chaptarr think the book is missing.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-12-03 03:57:34 -06:00

78 lines
7.9 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# Books stack (chaptarr / CWA / audiobookshelf / storyteller)
Lives in the `media` stack. Flow:
```
prowlarr ─► chaptarr ─► qbittorrent / nzbget ─► /storage1/complete
│
├─ 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)
```
| Service | Container:port | Host port | URL |
|---|---|---|---|
| chaptarr | `chaptarr:8789` | 8789 | https://chaptarr.ginnoir.com (native OIDC, LAN + tailnet only) |
| calibre-web-automated | `calibre-web-automated:8083` | 8083 | https://books.ginnoir.com (forward_auth, `/opds*` + `/kobo/*` bypass) |
| audiobookshelf | `audiobookshelf:80` | 13378 | https://audiobooks.ginnoir.com (native OIDC, LAN + tailnet only) |
| storyteller | `storyteller:8001` | 8001 | https://storyteller.ginnoir.com (forward_auth, `/api/*` bypass) |
## 1. Host prep (before the first deploy) — done 2026-10-18
Docker creates missing bind dirs as `root:root`, which breaks chaptarr/CWA/ABS (PUID 1000).
```bash
sudo mkdir -p /config/chaptarr /config/calibre-web-automated \
/config/audiobookshelf/{config,metadata} \
/storage1/Media/Books /storage1/Media/Audiobooks \
/storage1/complete/books-ingest /storage1/labdata/storyteller
sudo chown -R 1000:1000 /config/chaptarr /config/calibre-web-automated /config/audiobookshelf \
/storage1/Media/Books /storage1/Media/Audiobooks \
/storage1/complete/books-ingest /storage1/labdata/storyteller
```
## 2. Authentik — providers done 2026-10-18
`scripts/run-books-auth.sh` creates everything below (idempotent, runs `scripts/setup-books-auth.py` through `ak shell`). **Done on 2026-10-18.**
- **books / storyteller (Pattern B):** proxy providers `homelab-{books,storyteller}` (pk 44–45). They're `forward_single`, cloned from `homelab-sonarr`, attached to the embedded outpost, and each has an app with the same slug.
- **Chaptarr (Pattern A):** OIDC provider `homelab-chaptarr` (pk 47) plus app `chaptarr`, with the strict redirect URI `https://chaptarr.ginnoir.com/signin-oidc`. This replaced the forward_auth provider it started with (pk 43). The client ID and secret are in `stack.env` (`CHAPTARR_OIDC_CLIENT_*`).
In Chaptarr, go to Settings → General → Authentication, choose OIDC, and fill in:
- OIDC Authority: `https://auth.ginnoir.com/application/o/chaptarr/`
- Scopes: `openid profile email`
- Allowed Emails: your Authentik account email(s)
- Authentik's default email mapping sends `email_verified: false`, and Chaptarr requires `true`. So the chaptarr provider uses its own mapping, `homelab: OpenID 'email' (verified)`. The app is also bound to the `ginnoir` user, so no other account can match the allowlist by changing its email.
- Changing anything in `stack.env` makes Portainer recreate every media container. Don't do it while you're in the middle of a login.
- **Audiobookshelf (Pattern A):** OIDC provider `homelab-audiobooks` (pk 46) plus app `audiobooks`. Its strict redirect URIs are `https://audiobooks.ginnoir.com/audiobookshelf/auth/openid/{callback,mobile-redirect}` (current ABS serves under `/audiobookshelf`), the same pair without the prefix, and `audiobookshelf://oauth`. The client ID and secret are in `stack.env` (`ABS_OIDC_CLIENT_*`).
**Still to do in the ABS UI** (it keeps OIDC settings in its own database): go to Settings → Authentication → OpenID Connect.
- Issuer URL: `https://auth.ginnoir.com/application/o/audiobooks/`. Click *Auto-populate*, then paste the client ID and secret.
- Allowed mobile redirect URIs: `audiobookshelf://oauth`.
- Match existing users by username or email. Turn on auto-register if you want it.
- **CWA single sign-on (optional).** In Admin → Edit Basic Configuration → Feature Configuration, turn on *Allow Reverse Proxy Authentication* and set the header to `X-Authentik-Username`. The CWA usernames must match the Authentik usernames.
## 3. Post-deploy checklist
- [ ] **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.
- [ ] **CWA SMTP / Send-to-Kindle:** Admin → Edit Email Server Settings. Add the sender address to Amazon → *Manage Your Content and Devices* → *Personal Document Settings* → *Approved Personal Document E-mail List*. Set the user's Kindle email in their profile, then send the test book.
- [ ] **audiobookshelf:** create the root user and add a library pointed at `/audiobooks`. Scan it, then sign in from the phone app over Tailscale.
- [ ] **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/<Author>/`. 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/<Author>/` 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.
- GPU: Storyteller runs the CUDA 12.9 image on the P100 (`nvidia.com/gpu=0`, CDI). Upstream only tags CUDA images by commit SHA, so the tag is pinned and Watchtower is off. To bump it, pick a newer SHA from the registry's `amd64-cuda-12.9.0` repository. Don't use the CUDA 13.x images: they drop Pascal. The whisper build has no sm_60 kernels, so the first GPU run JIT-compiles PTX (~60 s). `CUDA_CACHE_PATH=/data/.nv-compute-cache` keeps that cache across restarts.
- Chaptarr is young and runs on `:latest` with Watchtower. If an update breaks it, pin a tag and add `com.centurylabs.watchtower.enable=false`.