needs-you

Guides

Server hubs (optional)

needs-you has three parts: the Needs You app on your Mac shows alerts, a hub stores them, and senders post them (App, hubs and senders). The app has a hub built in, which is all most setups need. This page is about the other place a hub can run: a server hub, the same hub, always on, on a Linux server you run. Add one when:

A hub is one Python file (hub/needs_you_hub.py, standard library and SQLite only) on stock python3 3.9+ (Ubuntu 22.04+, Debian 12+, macOS). Hubs replicate every write to each other, the app's built-in hub included once a server joins it, so a sender, the Mac or an invite link can use any of them. The wire contract is in API.

Two hubs in 10 minutes #

You need two always-on Linux machines with systemd and Tailscale (MagicDNS on), called hub-a and hub-b below, and this repo cloned on each. Everything installs under your home directory; no root except one loginctl command. Each hub then updates itself from GitHub releases, which needs gh 2.64 or later logged in as your user (gh auth login); pass --no-auto-update to stay on the checkout's code.

1. Hub A, with a new peer secret:

git clone <this repo> ~/needs-you && cd ~/needs-you
./scripts/install-hub.sh --user --peer http://hub-b.example.ts.net:8765 --generate-peer-secret

It prints the peer secret once. Save it to a file on hub B (over the tailnet, e.g. ssh hub-b 'umask 077; cat > ~/ny-secret', then paste), and keep it out of git and chat logs.

2. Hub B, with A as its peer and the same secret:

git clone <this repo> ~/needs-you && cd ~/needs-you
./scripts/install-hub.sh --user --peer http://hub-a.example.ts.net:8765 \
  --peer-secret-file ~/ny-secret --no-invite
rm ~/ny-secret

3. Linger. If the installer says lingering is off, run the command it prints on each hub, so the hub keeps running after you log out and starts at boot:

sudo loginctl enable-linger "$USER"

4. The first invite. Hub A printed an owner invite (needsyou://connect?...). Open it on the Mac and NeedsYou.app adds the hub. Then make a link for your servers on either hub:

needs-you-admin invite create my-servers --role sender --uses 5 --ttl 72

It prints the join URL, the one-liner, and a prompt to paste to an agent. Each machine that redeems the link gets its own token and is told about both hubs (NEEDS_YOU_URLS), so it fails over between them.

5. Check replication:

curl -s http://hub-b.example.ts.net:8765/v1/health        # stats, no token needed
needs-you-admin token list                                   # on hub B: tokens made on A show up

With a token, /v1/health also lists each peer's outbox_pending, last_push_ok, last_pull_ok and last_error. A healthy pair has outbox_pending 0 and a recent last_pull_ok. skipped_push and skipped_pull count replicated items one side couldn't read (usually a hub running an older version than its peer: upgrade it), with the last one in last_skipped; replication carries on past them, and the hub that skipped them applies them at its next start once it can read them. The hub's log names each one. A non-null blocked means a token or invite record (a revocation, say) one side can't read: those are never skipped, so replication in that direction waits for it (the log says BLOCKED). Upgrade the older hub; replication then resumes by itself.

With the app's built-in hub #

A server joins the app's built-in hub with a peer invite: a one-use link the Mac makes, which the server redeems for the pair's own replication secret. Nothing to copy by hand, and the secret never shows on a screen (ADR 0012).

1. On the Mac, make the link: **Settings → Built-in hub → Always-on hub → Add an always-on hub** shows the lines to run on the server and the link to paste, each with a copy button. The Mac must be on the tailnet; the link lasts an hour. From a terminal on the Mac instead:

python3 /Applications/NeedsYou.app/Contents/Resources/hub/needs_you_admin.py \
  --db ~/Library/Application\ Support/NeedsYou/hub.db \
  --public-url http://<this-mac>.<tailnet>.ts.net:8765 invite create my-server --role peer

2. On the server (Linux with systemd, python3 and Tailscale), the lines Settings showed (Copy), then the link when the installer asks for it (Copy link):

cd
curl -fsSLo install-hub.sh https://github.com/tayharris/needs-you/releases/download/vX.Y.Z/install-hub.sh
sudo bash install-hub.sh --join -
# Paste the peer invite link: http://<this-mac>.<tailnet>.ts.net:8765/join/nyi_...

They have no quote, bracket or pipe, so they survive a browser console that types a paste key by key. Logged in as root, leave out sudo. The installer reads the link at its prompt, so the invite code is in no command line: not in ps, not in the command sudo logs, not in your shell history. It's saved in your home folder on purpose: run from a file, the installer treats the folder above it as a checkout when that holds hub code, and above a home folder only root can write. It ends with needs-you-hub is up; the Mac's Always-on hub list shows the server within a minute. The hub's invite carries the same lines (install_steps, also on the link's page and in needs-you-admin invite create), plus one line for scripts and agents, with no one to paste the link: (curl -fsSL <install-hub.sh URL> && echo '<link>') | sudo bash -s -- --join -.

vX.Y.Z is the release the Mac app runs. The installer comes from that GitHub release, and so does all the code it installs: it downloads the release's server tarball for its own version, checks it against the release's SHA256SUMS and release-manifest.json (and, when gh is installed, that manifest's build provenance; without gh it talks to GitHub's own hosts over https only), refuses a tarball for any other version, and installs nothing if a check fails or GitHub can't be reached. The Mac's hub supplies only the link: no code comes from it, so a hub can't make a server install anything else. It installs and starts a system-wide hub, pairs it with the Mac's hub, and prints no secret. The hub then updates itself from GitHub releases, which needs gh 2.64 or later logged in as root (sudo gh auth login, or GH_TOKEN in a drop-in); until then each update run logs why it installed nothing. Add --no-auto-update after --join - to opt out. A development build of the app has no matching release: install from a checkout then. From a checkout (or the release's server tarball), ./scripts/install-hub.sh --user --join - does the same as your user: paste the link when it asks (from a script, pipe the link in on stdin). Run as root, a checkout is first copied to a private directory, refusing symlinks and anything another user could write (the files or any directory above them), and only that copy is installed. On a server that already runs a hub (alone, or in a mesh with its own peer_secret), run needs-you-admin peer join - instead and paste the link when it asks; the running hub picks it up within 5 seconds and its other peers are left as they are.

Then:

The server's public_url must be its MagicDNS name (the installer's default with Tailscale), so the Mac reaches it by name whatever its tailnet IP. The Mac's hub is named the same way.

A Mac that sleeps for days still learns what was resolved meanwhile: a closed item's text is purged a day after it closed, but a text-free tombstone stays for 30 days (housekeeping), and the Mac's hub pulls it when it wakes. Only after 30 days away can an item resolved on the server stay open on the Mac until you close it.

Joining one server to another works the same way: needs-you-admin invite create hub-b --role peer on one, the lines it prints (install-hub.sh --join -, or needs-you-admin peer join -, then the link when it asks) on the other.

A pairing can't be taken over: a peer invite redeemed with the URL or hub id of a hub that is already paired is refused (409), and so is a join whose answer names another paired hub. To pair the same hub again, or under a new URL, remove it first (Remove in Settings, needs-you-admin peer remove), then make a new peer invite. Both sides accept a peer only at https, or plain http to a tailnet name or address (or loopback).

What install-hub.sh --user sets up #

PathWhat
~/.local/share/needs-you/The code: hub/, cli/ and the integration files the hub serves at /dl/
~/.config/needs-you/hub.jsonConfig, mode 600 (holds the peer secret)
~/.local/state/needs-you/hub.dbSQLite database (WAL, incremental auto-vacuum)
~/.config/systemd/user/needs-you-hub.servicesystemctl --user unit, Restart=always
~/.local/bin/needs-you-adminThe admin tool, preset to this config
~/.config/needs-you/hub-update.jsonAutomatic update settings, mode 600
~/.config/systemd/user/needs-you-hub-update.{service,timer}The automatic updater, every 6 hours
~/.local/state/needs-you/hub-update.lock, hub-update-failed.jsonThe updater's lock, and the releases that failed to install
~/.local/share/needs-you.previousThe code from before the last automatic update, for a rollback
~/.config/systemd/user/needs-you-hub-update.pathStarts the updater when the owner asks for an update (below)

Options:

OptionDefaultMeaning
--usersystem installInstall for the current user (recommended).
--bind ADDR127.0.0.1 + tailscale ip -4Listen addresses, repeatable or comma-separated. 0.0.0.0/:: are refused.
--port N8765TCP port.
--hub-id IDhostname -sUnique per hub (letters, digits, ., _, -).
--public-url URLhttp://<MagicDNS name>:PORTHow others reach this hub. Used in invite links and hub_urls.
--peer URLnoneAnother hub's public URL. Repeatable; replaces the peer list.
--peer-secret-file FThe shared replication secret, from a file.
--peer-secret SThe same, inline (visible in ps; prefer the file).
--generate-peer-secretMake a new secret and print it once.
--join -Pair with the hub that made this peer invite (above), reading its link from stdin. No owner invite is printed. --join LINK works too, but puts the code in ps and sudo's log.
--reconfigureoffRebuild the config from defaults + flags (keeps the secret).
--no-startoffInstall files and config only.
--no-inviteoffDon't print the first owner invite.
--no-auto-update / --auto-updateonTurn automatic updates off or on.
--update-channel Cstablestable, or prerelease to take pre-releases too.
--update-soak-hours N24Wait this long after a release is published before installing it (0–720).
--update-gh PATHgh on PATHThe gh that checks each release (2.64 or later, logged in).

Re-running upgrades in place: the code and units (hub and updater) are replaced, hub.json and hub-update.json are kept with only the flags you passed applied to them, the update timer is turned on or off to match, the database is untouched, and the service restarts. The owner invite is printed only when the config is first created.

Logs go to the journal only (journalctl --user -u needs-you-hub -f); the hub writes no log files.

System-wide install (alternative) #

sudo ./scripts/install-hub.sh --peer http://hub-b.example.ts.net:8765 --generate-peer-secret

Same options without --user. It creates a needs-you system user and uses /opt/needs-you (code), /etc/needs-you/hub.json (config, 640 root:needs-you), /var/lib/needs-you/hub.db, the sandboxed unit /etc/systemd/system/needs-you-hub.service (read-only system, no home access, no capabilities, syscall filter), and the wrapper /usr/local/bin/needs-you-admin, which runs the admin tool as needs-you. Logs: journalctl -u needs-you-hub. It also installs the automatic updater: /etc/systemd/system/needs-you-hub-update.{service,timer} (run as root, since it re-runs the installer), its settings in /etc/needs-you/hub-update.json, and its lock and failed-release record in /etc/needs-you/; the code from before an update is kept in /opt/needs-you.previous. It needs gh 2.64 or later logged in as root. Its log: journalctl -u needs-you-hub-update.

Config reference #

hub.json is plain JSON (see deploy/hub.example.json). Every key can also be set by a flag on needs_you_hub.py, so no file is required: the named flags, or --set KEY=VALUE for anything else (VALUE is parsed as JSON when it can be). Every key, with its flag, default and what it takes, is in Configuration → hub.json, with hub-update.json and every environment variable. The hub refuses to start with a value of the wrong type or out of range (naming the key), and warns about a key it doesn't know. Check a config without starting anything:

python3 ~/.local/share/needs-you/hub/needs_you_hub.py --check-config --config ~/.config/needs-you/hub.json

Restart after editing: systemctl --user restart needs-you-hub (or sudo systemctl restart needs-you-hub).

Use the MagicDNS name, not the IP #

Everything that talks to a hub uses its public_url, a MagicDNS name over plain http such as http://hub-a.example.ts.net:8765, not http://100.x.y.z:8765. The Mac app only allows plain http to *.ts.net and local names, and the name survives the tailnet IP changing. Traffic is still encrypted by WireGuard. The IP belongs only in bind.

Invites and tokens #

needs-you-admin invite create my-server --role sender --uses 3 --ttl 72   # servers and agents
needs-you-admin invite create mac --role owner                            # a Mac app
needs-you-admin invite list            # live invites: uses left, expiry
needs-you-admin invite revoke my-server
needs-you-admin token list             # name, role, state, open items
needs-you-admin token revoke my-server-build-1
needs-you-admin token add ci-myrepo --role sender                          # a bare token, printed once
needs-you-admin invite create hub-b --role peer       # another hub joins this one (one use, 1 h)
needs-you-admin peer join -                            # this hub joins another (paste the link)
needs-you-admin peer list                              # peers: config and invite, never secrets
needs-you-admin peer remove hub-b                      # by hub id, URL or name (invite peers)

Roles: sender posts and resolves; reader reads, resolves, dismisses and answers a card's question by picking its options; owner is a reader that can also create invites and type an answer's own words ("Other…") (the Mac app). Codes and tokens are stored as sha256 hashes and printed once. Revoking an invite doesn't revoke tokens it already minted. A peer invite is for another hub, not a machine: it stays on this hub (it isn't replicated) and mints no token.

The admin tool writes straight to the database (safe while the hub runs, thanks to WAL) and queues the change for replication, so an invite or token made on one hub works on all of them within seconds. A link from one hub can be redeemed on any; see API for the small double-spend window.

Housekeeping #

The hub keeps itself small and keeps little: a closed item's text (title, body, links, steps, question, answer, source) is purged text_retention_hours (24) after it closed, leaving a tombstone (id, key, status, times, origin hub) so peers and clients that were away still learn it closed; tombstones are deleted after retention_days (30). The purge runs on the hub's own clock, a peer's copy can't bring purged text back, freed space is overwritten (secure_delete), and the backups made before a migration (hub.db.bak-N) are purged the same way. Stale peer outbox rows go after 7 days, expired invites at the next pass and revoked ones a day after the revocation (so it replicates), with a WAL checkpoint and incremental vacuum every 10 minutes and a full VACUUM at most daily. Replicated records older than the cutoff are refused, so a peer can't bring purged items back. GET /v1/health shows db_bytes, item counts and outbox depth.

Resource use #

Measured 2026-10-07. The Mac numbers are the running app and its bundled hub on an Apple Silicon MacBook Pro (macOS 15, Python 3.9), after a day of normal use. The server numbers are a throwaway hub on a desktop Linux machine (8-core AMD Ryzen, Python 3.12, no peers).

WhatMeasuredHow
Mac app, idle0.4% of one core (0.46 s of CPU in 120 s), 55 MB memory footprintps CPU time over two idle minutes; footprint
Mac's hub, idle0.2% of one core (0.21 s in 120 s), 27 MB footprintsame
Mac's hub.db0.9 MB with 138 items (0.2 MB database + 0.7 MB WAL)ls
Server hub, idleunder 0.1% of one core (0.03%), 33 MB RSS/proc CPU time over 60 s
1,000 posts, one after another1.2 s (about 850 a second); 1.1 ms median, 2.2 ms p99; hub at 77% of one core during the burst; RSS 33 to 34 MBPOST /v1/items over urllib
Database growthabout 600 bytes per item (realistic title, body, one link); the WAL reached 4.8 MB during the burst and is truncated at the next maintenance passfile size after wal_checkpoint(TRUNCATE)
Mac poll, nothing new82 bytes, 1 msGET /v1/items?since=
Mac full poll, 1,000 open items630 KB, 36 msGET /v1/items?status=open
needs-you addabout 120 ms per call (Python start-up and imports), the same when failing over from a refused hub or queuing offline (210 bytes per queued request)wall time of 20 calls

Nothing else runs: no Docker, no database server, no pip packages, no cloud account. Network use is a poll every 30 seconds (NEEDS_YOU_POLL_SECONDS), a full snapshot every 10th poll, and one /v1/stream connection that carries a 15-second ping when idle. Peered hubs push writes as they happen and pull each peer once a minute. Disk stays bounded by the housekeeping above and by max_open_per_token (60 open items per sender token); a failover that waits on an unreachable (not refused) hub costs up to NEEDS_YOU_TIMEOUT (3 s) per hub.

Upgrading #

Upgrades never lose config or data. A hub installed by install-hub.sh 0.5.1 or later upgrades itself (automatic updates, on by default; it needs gh 2.64 or later, logged in). An older hub gets the updater the next time a 0.5.1 or later install-hub.sh runs on it. To upgrade by hand from a checkout:

cd ~/needs-you && git pull && ./scripts/install-hub.sh --user     # or: sudo ./scripts/install-hub.sh

A hub installed from a release (the --join - command above) has no checkout: run the newer release's install-hub.sh the same way, without --join (the config and database are kept).

Automatic updates #

15 minutes after boot and then every 6 hours, each run up to 30 minutes late at random (needs-you-hub-update.timer), the updater (hub/needs_you_hub_update.py) asks GitHub, through gh, for the newest release on the hub's channel. When one is newer than the installed hub and was published at least the soak time ago (24 hours by default), it:

  1. downloads that release's install-hub.sh, SHA256SUMS and release-manifest.json, and checks the installer against both and its build provenance: built by this repo's release workflow, from that tag, on a GitHub-hosted runner (gh attestation verify --deny-self-hosted-runners);
  2. runs that installer the way the hub was installed (--user or system-wide), which checks the release's server tarball the same way, keeps hub.json, the update settings and the database, and restarts the hub;
  3. waits up to a minute for /v1/health to answer with the new version. If it doesn't, it stops the hub, puts the previous code back (it keeps a copy next to it, ~/.local/share/needs-you.previous or /opt/needs-you.previous system-wide), restores the database from the hub's own pre-migration backup (hub.db.bak-<schema>) if the new version had already migrated it, restarts the hub and checks it answers. A release that failed is remembered (hub-update-failed.json in ~/.local/state/needs-you/, or /etc/needs-you/ system-wide) and not tried again: until a newer release is out, each run logs that it's skipped and exits non-zero; the next newer one is tried. Delete that file to retry the failed one.

Nothing is installed without build provenance, so automatic updates need **gh 2.64 or later, logged in** (gh auth login; system-wide installs: logged in as root, or GH_TOKEN in a drop-in). With no gh, or an older one (Ubuntu 24.04 ships 2.45), the updater installs nothing and says why in its log; point it at a newer one with --update-gh PATH. It never reads or prints a token, peer secret or invite code.

The settings live in hub-update.json next to hub.json; change them by re-running the installer with the flags above (a re-run without them keeps them):

{"auto_update": true, "channel": "stable", "soak_hours": 24, "gh": ""}

A file that can't be read, or has a value out of range, turns automatic updates off.

journalctl --user -u needs-you-hub-update          # what each run did (system: without --user)
python3 ~/.local/share/needs-you/hub/needs_you_hub_update.py --mode user --check   # what it would install now
systemctl --user start needs-you-hub-update.service                                 # update now (respects the soak)
./scripts/install-hub.sh --user --no-auto-update                                    # off

System-wide: sudo systemctl start needs-you-hub-update.service, and the installer without --user. Turning it off by re-running the installer also installs that checkout's (or release's) code, so pull first: an older checkout is a downgrade. Or set "auto_update": false in hub-update.json: the next run does nothing, and a re-run of the installer without --auto-update keeps it off.

Update now from the Mac #

Settings → Updates → Machines and hubs on the Mac lists each server hub with its version and a Request update button (ADR 0013, POST /v1/hub/update, owner token only). The request carries nothing: the hub drops a flag file, hub-update-request, next to its database, and needs-you-hub-update.path starts the updater, which removes the flag and runs exactly as on its timer except that it doesn't wait out the soak. Every check (channel, sums, manifest, build provenance, failed releases, rollback) stays. Each run writes hub-update-status.json next to hub.json (what it did, one log line, no secrets), which is how the Mac shows "Updated to 0.5.2" or why it failed. One request per 15 minutes is accepted; the updater honours one per 10 minutes. It needs automatic updates on. The same from a shell on the server: touch <the database's directory>/hub-update-request.

A hub installed from a checkout updates from GitHub releases too, replacing the checkout's code at the next newer release; pass --no-auto-update to keep tracking the checkout. Peered hubs each update on their own schedule; keep them on the same channel so they stay a version apart at most (see the schema notes above).

Operations #

Development #

python3 hub/needs_you_hub.py --db /tmp/ny.db --owner-token-file <(echo dev-owner-token-123456)
python3 hub/needs_you_admin.py --db /tmp/ny.db invite create me
/usr/bin/python3 -m unittest discover -s tests    # also with macOS /usr/bin/python3 (3.9)

Code must stay Python 3.9-compatible and standard-library only: from __future__ import annotations, no match, no runtime X | Y unions, no tomllib.

This page is docs/HUB.md in the repo. View or edit it on GitHub.