Null-DRM-Official/docs/streamd-server-setup.md
404errordeveloper a091922efa
All checks were successful
release / build-and-upload (push) Successful in 7m2s
streamd v0.2.2: session uptimes, egress DNS, Support, agent/Widevine
Dashboard Live uptimes + Recent runs from stream_sessions; overview.recent_sessions.
WireGuard netns resolv.conf + missing-deps WARN. Support donations card.
Agent start/stop/update, job_backoff default off, wvkey ensure/venv, phonecap retries,
modhost YAML enrich, DRM SetCredentials requires keys.
2026-10-10 19:26:39 +02:00

18 KiB
Raw Blame History

Streamd + agent on a Linux server (for dummies)

This guide is only for streamd (streamd serve) and the agent (streamd agent run) on a Linux box. Copy-paste the commands. Change the bits in CAPS or <angle brackets>.

You do not need Go, git, or a full repo checkout. One binary is enough.

For the deep reference (every flag, every API route), see streamd.md.


What each piece does

Piece Command Job
streamd streamd serve Dashboard + API + pulls the MPD and serves HLS
agent streamd agent run Optional. Uses a phone to refresh MPD/keys when they expire

If you already have a working MPD URL and Widevine keys (KID:KEY), you can run streamd alone. Start the agent later when you want automatic refresh.


0. What you need

  • A Linux server (x86_64 or ARM64)
  • SSH access
  • curl (almost every distro has it)
  • Outbound HTTPS (streamd downloads ffmpeg / N_m3u8DL-RE on first start)

Check your CPU type:

uname -m
  • x86_64 → download streamd-linux-amd64
  • aarch64 → download streamd-linux-arm64

1. Make a folder and download the binary

mkdir -p ~/null-drm
cd ~/null-drm

Grab a rolling channel build (always the newest — no version pin). Pick one block for your CPU. Pin with a concrete tag (v0.1.5, v0.2.0-beta.1, …) when you need a fixed install.

Linux Intel / AMD 64-bit (stable)

curl -fL -o streamd \
  "https://git.nulldrm.com/nulldrm/Null-DRM-Official/releases/download/stable/streamd-linux-amd64"

Linux ARM 64-bit (stable) — Raspberry Pi 4+, many cloud ARM VMs

curl -fL -o streamd \
  "https://git.nulldrm.com/nulldrm/Null-DRM-Official/releases/download/stable/streamd-linux-arm64"

Beta channel (Linux Intel / AMD 64-bit pre-release)

curl -fL -o streamd \
  "https://git.nulldrm.com/nulldrm/Null-DRM-Official/releases/download/beta/streamd-linux-amd64"

Make it executable and check it works:

chmod +x streamd
./streamd help

You should see a list of commands including serve and agent.


2. Start streamd (first time)

cd ~/null-drm

./streamd serve start \
  --bind 0.0.0.0:8083 \
  --admin-user admin \
  --admin-pass 'CHANGE_ME_NOW'

What happens:

  1. streamd writes streamd.yaml next to the binary (bind, data, log/pid paths, update channel) so the next start remembers your settings
  2. Starts the WebUI in the background (pid file + log file)
  3. On first boot, downloads ffmpeg / N_m3u8DL-RE / mp4decrypt into bin/

Check it:

./streamd serve status
./streamd serve stop
./streamd serve start          # uses streamd.yaml — no flags needed next time

Edit streamd.yaml any time (then ./streamd serve restart):

bind: 0.0.0.0:8083
data: .cache/streamd
log_level: info
log_file: streamd.log
pid_file: streamd.pid
channel: stable          # used by: streamd serve update
keep_old: 10

Example file in the repo: docs/examples/streamd.yaml.

Foreground (debug)

./streamd serve --bind 0.0.0.0:8083 --admin-user admin --admin-pass 'CHANGE_ME_NOW'
# or: ./streamd serve run --bind …

Also writes streamd.yaml on first run if missing. Ctrl+C stops it.

--data is optional. If you omit it, streamd:

  1. uses $STREAMD_DATA when that env var is set, else
  2. reuses ./.cache/streamd when that folder already exists, else
  3. reuses <install>/.cache/streamd next to the binary when that folder exists, else
  4. creates ./.cache/streamd
Flag / yaml key Meaning
--bind / bind Listen address (0.0.0.0:8083 on a server)
--data / data DB / HLS / logs dir
--admin-user / --admin-pass First admin account (only when the DB is empty)

You will see a startup warning about binding non-loopback. That is expected on a server. Prefer putting a reverse proxy (Caddy / nginx) with TLS in front later.

Open in your browser (use the server IP):

http://YOUR_SERVER_IP:8083

Sign in with admin / the password you set.

Firewall tip: if the page does not load, open TCP 8083:

# Ubuntu ufw example
sudo ufw allow 8083/tcp
sudo ufw reload

Layout after first start:

~/null-drm/
  streamd                 # the binary
  streamd.yaml            # auto-written on first serve / serve start
  streamd.log
  streamd.pid
  old/                    # previous binaries after `serve update`
  .cache/streamd/         # database, HLS, logs, modules
  .cache/agent/           # created by agent
  agent.yaml              # you create this for the agent
  data/                   # optional .wvd for key fetch
  bin/                    # auto-downloaded ffmpeg, N_m3u8DL-RE, mp4decrypt

3. Create an API key for the agent (and for curl)

In the dashboard:

  1. Open Settings → API keys (or People & keys)
  2. New API key
  3. Role: operator
  4. Copy the secret once (ndk_…) — it is shown only then

You will paste that into agent.yaml and into curl examples below. Call it YOUR_API_KEY in the rest of this guide.


4. Add an MPD stream and start it

Option A — dashboard (easiest)

  1. Go to Streams → Add stream (or Create)
  2. Basics: name like city-news, leave Enabled checked
  3. Source: paste the MPD URL (https://…/manifest.mpd)
  4. Paste keys if the stream is encrypted — one KID:KEY per line. Leave empty for clear streams (e.g. some BBC)
  5. Optional proxy: socks5://127.0.0.1:1080 if origin needs a UK/IE SOCKS hop
  6. Create the stream
  7. Open the stream → Start (or it may already be running if Enabled + MPD are set)

When it is healthy, copy the play URL from the dashboard (Copy button), or use:

http://YOUR_SERVER_IP:8083/hls/city-news/index.m3u8

HD / SD variants (if you enabled them) are:

http://YOUR_SERVER_IP:8083/hls/city-news-hd/index.m3u8
http://YOUR_SERVER_IP:8083/hls/city-news-sd/index.m3u8

Option B — curl (no browser)

Create:

export STREAMD_API_KEY='YOUR_API_KEY'

curl -sS -X POST "http://127.0.0.1:8083/api/streams" \
  -H "Authorization: Bearer $STREAMD_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "name": "city-news",
    "title": "City News",
    "mpd": "https://example.com/path/manifest.mpd",
    "key": "KIDHEX:KEYHEX",
    "enabled": true,
    "drm_mode": "auto"
  }'

Start (use the numeric id from the create response, or from GET /api/streams):

curl -sS -X POST "http://127.0.0.1:8083/api/streams/1/start" \
  -H "Authorization: Bearer $STREAMD_API_KEY"

List streams:

curl -sS "http://127.0.0.1:8083/api/streams" \
  -H "Authorization: Bearer $STREAMD_API_KEY"

Push fresh credentials later (what the agent does after a phone capture):

curl -sS -X POST "http://127.0.0.1:8083/api/streams/1/credentials" \
  -H "Authorization: Bearer $STREAMD_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "mpd": "https://example.com/path/manifest.mpd",
    "key": "KIDHEX:KEYHEX\nKIDHEX2:KEYHEX2"
  }'

Health check (no auth):

curl -sS "http://127.0.0.1:8083/api/health"

5. Agent (optional — auto refresh with a phone)

Skip this section if you will paste MPD/keys yourself forever.

What the agent needs

  • streamd already running and reachable
  • An operator API key
  • adb on the server PATH
  • A rooted phone with the streaming app already installed (agent never installs apps)
  • USB debugging authorised (adb devices shows device)
  • Provider modules uploaded in the streamd Modules page (drag-drop .zip); agents pull them with sync_modules: true
  • A .wvd at data/device.wvd (or set wvd: in the config) for key fetch

Config file

cd ~/null-drm
nano agent.yaml

Paste (edit the URL and key):

streamd_url: http://127.0.0.1:8083
api_key: "YOUR_API_KEY"
poll_interval_sec: 30
data_dir: .cache/agent
workers: 1
max_attempts: 5
capture_wait_sec: 180
devices: []
# wvd: data/device.wvd
# agent_id: my-server

Save, then run:

cd ~/null-drm
./streamd agent run --config agent.yaml

Useful checks:

./streamd agent devices
./streamd agent status
./streamd agent enqueue --stream city-news --reason manual

In the dashboard, Refresh keys on a stream asks connected agents to capture now.


6. Keep it running when you close the terminal

If you close SSH while streamd serve / serve run is in the foreground, it dies. Use streamd serve start (Method A) so it survives logout.

Built into the binary. Reads streamd.yaml, writes pid + log, safe to close SSH:

cd ~/null-drm
./streamd serve start
./streamd serve status
./streamd serve stop
./streamd serve restart
tail -f streamd.log          # Ctrl+C leaves streamd running

Upgrade later with ./streamd serve update (see §10).

Optional thin wrappers (same commands) if you already curl’d them:

curl -fL -o streamd-bg.sh \
  "https://git.nulldrm.com/nulldrm/Null-DRM-Official/raw/branch/main/scripts/streamd-bg.sh"
chmod +x streamd-bg.sh
./streamd-bg.sh start        # → streamd serve start

Agent (still separate; needs agent.yaml):

nohup ./streamd agent run --config agent.yaml >agent.log 2>&1 &
# or: ./streamd-bg.sh start-agent

Method B — screen

sudo apt-get update && sudo apt-get install -y screen   # Debian/Ubuntu
# Fedora: sudo dnf install screen

Start streamd inside a named screen:

cd ~/null-drm
screen -S streamd
./streamd serve --bind 0.0.0.0:8083

Detach without killing it: press Ctrl+A, then D.

Come back later:

screen -r streamd

Second screen for the agent:

screen -S agent
cd ~/null-drm
./streamd agent run --config agent.yaml
# Ctrl+A then D

List sessions: screen -ls

Method C — tmux (same idea)

sudo apt-get install -y tmux
cd ~/null-drm
tmux new -s streamd
./streamd serve --bind 0.0.0.0:8083
# Detach: Ctrl+B then D
# Reattach: tmux attach -t streamd

Create a user unit (no root binary needed). Paths assume install in /home/ubuntu/null-drm — change User=, paths, and password as needed.

sudo tee /etc/systemd/system/streamd.service >/dev/null <<'EOF'
[Unit]
Description=Streamd (streamd serve)
After=network-online.target
Wants=network-online.target

[Service]
Type=simple
User=ubuntu
WorkingDirectory=/home/ubuntu/null-drm
# Foreground under systemd (do not use `serve start` here — systemd is the supervisor).
ExecStart=/home/ubuntu/null-drm/streamd serve run --config /home/ubuntu/null-drm/streamd.yaml
Restart=on-failure
RestartSec=5
# Optional first-boot admin (ignored once users exist):
# Environment=STREAMD_ADMIN_PASS=CHANGE_ME

[Install]
WantedBy=multi-user.target
EOF

sudo tee /etc/systemd/system/streamd-agent.service >/dev/null <<'EOF'
[Unit]
Description=Streamd credentials agent
After=network-online.target streamd.service
Wants=network-online.target
Requires=streamd.service

[Service]
Type=simple
User=ubuntu
WorkingDirectory=/home/ubuntu/null-drm
ExecStart=/home/ubuntu/null-drm/streamd agent run --config /home/ubuntu/null-drm/agent.yaml
Restart=on-failure
RestartSec=5

[Install]
WantedBy=multi-user.target
EOF

sudo systemctl daemon-reload
sudo systemctl enable --now streamd.service
# when ready for the agent:
# sudo systemctl enable --now streamd-agent.service

Useful commands:

sudo systemctl status streamd
sudo journalctl -u streamd -f
sudo systemctl restart streamd
sudo systemctl stop streamd

Same pattern with streamd-agent for the agent unit.


7. Per-stream WireGuard egress (optional)

Use this when some streams must exit via another country (e.g. London) while SSH and the dashboard stay on the server’s normal IP.

Host packages

# Debian/Ubuntu
sudo apt-get install -y wireguard wireguard-tools iproute2 microsocks
# Fedora: sudo dnf install wireguard-tools iproute microsocks

streamd serve must be allowed to create network namespaces (CAP_NET_ADMIN / CAP_SYS_ADMIN, or run as root). A full-tunnel client conf (AllowedIPs = 0.0.0.0/0) is fine — traffic is isolated inside streamd-<name> netns.

On Up, streamd also writes /etc/netns/streamd-<name>/resolv.conf with public resolvers (1.1.1.1, 1.0.0.1, 8.8.8.8). Without that, SOCKS hostname lookups fail when the host uses systemd-resolved’s 127.0.0.53 stub (unreachable inside the netns). Writing under /etc/netns/ needs the same privileges as ip netns. Teardown removes that directory with the namespace.

If ip, wg, or microsocks/gost are missing from PATH, streamd serve logs a WARN at startup so WireGuard profiles fail clearly instead of silently.

Dashboard

  1. Settings → Egress tunnels → Add profile
  2. Name london, kind WireGuard, paste your client .conf (e.g. vps-london.conf)
  3. Up, then Test IP (should show the London egress address)
  4. On each stream (Config): Egress tunnel = london (leave others on Direct)

Raw Origin proxy URL still overrides the dropdown when set.

curl equivalent

export STREAMD_API_KEY='YOUR_API_KEY'

curl -sS -X POST "http://127.0.0.1:8083/api/egress" \
  -H "Authorization: Bearer $STREAMD_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"name":"london","kind":"wireguard","enabled":true}'

# Upload conf (JSON). Do not commit real keys to git.
python3 - <<'PY'
import json, pathlib, urllib.request, os
conf = pathlib.Path("vps-london.conf").read_text()
req = urllib.request.Request(
  "http://127.0.0.1:8083/api/egress/london",
  data=json.dumps({"conf": conf}).encode(),
  headers={
    "Authorization": "Bearer " + os.environ["STREAMD_API_KEY"],
    "Content-Type": "application/json",
  },
  method="PUT",
)
print(urllib.request.urlopen(req).read().decode())
PY

curl -sS -X POST "http://127.0.0.1:8083/api/egress/london/up" \
  -H "Authorization: Bearer $STREAMD_API_KEY"
curl -sS -X POST "http://127.0.0.1:8083/api/egress/london/test" \
  -H "Authorization: Bearer $STREAMD_API_KEY"

curl -sS -X PATCH "http://127.0.0.1:8083/api/streams/1" \
  -H "Authorization: Bearer $STREAMD_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"egress":"london"}'

Conf on disk: .cache/streamd/egress/london/wg.conf (mode 0600). Add dublin the same way as a second profile.


8. Quick “am I done?” checklist

cd ~/null-drm

# binary runs
./streamd help

# streamd answers
curl -sS http://127.0.0.1:8083/api/health

# at least one stream exists and is enabled
curl -sS http://127.0.0.1:8083/api/streams \
  -H "Authorization: Bearer YOUR_API_KEY"

# HLS playlist exists after start (name = stream name)
curl -sI "http://127.0.0.1:8083/hls/city-news/index.m3u8"

Play the m3u8 in VLC / ffplay / any HLS player using the server IP URL.


9. Common problems

Symptom Fix
Permission denied running ./streamd chmod +x streamd
Browser cannot open the page Use --bind 0.0.0.0:8083, open firewall port 8083, check curl from the server itself
Stream will not start MPD must be http:// or https://. Encrypted streams need KID:KEY lines
Agent does nothing Operator API key wrong; stream Enabled; phone in adb devices as device; app installed
Dies when SSH closes Use ./streamd serve start (or screen/tmux/systemd) from §6
text file busy / cannot replace streamd Use ./streamd serve update (stops first) or serve stop then replace — see §10
Deps download fails Server needs outbound HTTPS; or place ffmpeg / N_m3u8DL-RE / mp4decrypt on PATH / in bin/ and use --skip-deps only if you already have them
Want loopback only + proxy Bind 127.0.0.1:8083 and put Caddy/nginx in front with TLS

10. Stopping / upgrading

Built into the binary — one command stops, downloads, archives the old binary under ./old/, and restarts:

cd ~/null-drm
./streamd serve update              # stable channel (from streamd.yaml `channel:`)
./streamd serve update --beta
./streamd serve update --tag v0.2.0
./streamd serve update --no-restart # replace only; then: ./streamd serve start
./streamd serve status

What serve update does:

  1. Stops a background serve if it is running (pid file)
  2. Downloads streamd-linux-amd64 or streamd-linux-arm64 (or the yaml asset:) from the stable / beta / --tag release
  3. Smoke-tests the new file (streamd help)
  4. Moves ./streamd → ./old/streamd.YYYYMMDDTHHMMSSZ
  5. Installs the new binary and starts it again (unless --no-restart)

streamd.yaml / .cache/streamd are left alone.

Layout after a few upgrades:

~/null-drm/
  streamd
  streamd.yaml
  old/
    streamd.20261010T153012Z
    streamd.20261012T091500Z
  .cache/streamd/

Roll back:

cd ~/null-drm
./streamd serve stop
mv streamd "old/streamd.failed.$(date -u +%Y%m%dT%H%M%SZ)"
cp old/streamd.20261010T153012Z streamd
chmod +x streamd
./streamd serve start

screen / tmux

screen -r streamd          # or: tmux attach -t streamd
# Ctrl+C — detach is not enough; the process must exit
./streamd serve update --no-restart
# then start again in screen, or:
./streamd serve start

systemd

sudo systemctl stop streamd
./streamd serve update --no-restart
sudo systemctl start streamd
sudo systemctl status streamd

Optional shell wrappers

./streamd-update.sh --beta     # → streamd serve update --beta
./streamd-bg.sh stop           # → streamd serve stop

Back up .cache/streamd/streamd.db before big upgrades if you want an extra safety copy. The updater never touches the data directory.


See also