streamd: serve start/stop/update, streamd.yaml, egress, module panel fixes
- Add streamd serve start|stop|restart|status|update with auto-written streamd.yaml - Panel modules: STREAMD_MODULES_DIR for describe, YAML channel fallback, textarea value fix - Per-stream WireGuard/SOCKS egress profiles + Settings UI - Drop drm-* from release builds; track streamd-bg.sh / streamd-update.sh wrappers - Docs: streamd-server-setup lifecycle and update flow
This commit is contained in:
parent
da8e1123ec
commit
8fc7e4c0b8
57 changed files with 4031 additions and 257 deletions
|
|
@ -81,50 +81,75 @@ chmod +x streamd
|
|||
|
||||
You should see a list of commands including `serve` and `agent`.
|
||||
|
||||
Optional layout after first run:
|
||||
|
||||
```text
|
||||
~/null-drm/
|
||||
streamd # the binary
|
||||
.cache/streamd/ # created by serve (database, HLS, logs)
|
||||
.cache/agent/ # created by agent
|
||||
agent.yaml # you create this for the agent
|
||||
data/ # optional .wvd for key fetch
|
||||
modules/ # optional provider zips (agent / capture)
|
||||
bin/ # auto-downloaded ffmpeg, N_m3u8DL-RE, mp4decrypt
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## 2. Start streamd (first time)
|
||||
|
||||
Pick a password. Create the first admin account on the command line so you are
|
||||
not stuck hunting a setup token in the logs:
|
||||
### Recommended — background with `streamd.yaml`
|
||||
|
||||
```bash
|
||||
cd ~/null-drm
|
||||
|
||||
./streamd serve \
|
||||
./streamd serve start \
|
||||
--bind 0.0.0.0:8083 \
|
||||
--data .cache/streamd \
|
||||
--admin-user admin \
|
||||
--admin-pass 'CHANGE_ME_NOW'
|
||||
```
|
||||
|
||||
What those flags mean:
|
||||
What happens:
|
||||
|
||||
| Flag | Meaning |
|
||||
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:
|
||||
|
||||
```bash
|
||||
./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`):
|
||||
|
||||
```yaml
|
||||
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`](examples/streamd.yaml).
|
||||
|
||||
### Foreground (debug)
|
||||
|
||||
```bash
|
||||
./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 0.0.0.0:8083` | Listen on all interfaces so you can open it from your PC |
|
||||
| `--data .cache/streamd` | Where the DB, HLS files, and logs live |
|
||||
| `--admin-user` / `--admin-pass` | First admin account (only used when the DB is empty) |
|
||||
| `--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.
|
||||
|
||||
On first start, streamd downloads ffmpeg, N_m3u8DL-RE, and mp4decrypt into
|
||||
`bin/`. Wait until the log says it is listening.
|
||||
|
||||
Open in your browser (use the server IP):
|
||||
|
||||
```text
|
||||
|
|
@ -141,6 +166,22 @@ sudo ufw allow 8083/tcp
|
|||
sudo ufw reload
|
||||
```
|
||||
|
||||
Layout after first start:
|
||||
|
||||
```text
|
||||
~/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)
|
||||
|
|
@ -294,9 +335,41 @@ In the dashboard, **Refresh keys** on a stream asks connected agents to capture
|
|||
|
||||
## 6. Keep it running when you close the terminal
|
||||
|
||||
If you close SSH while `streamd serve` is in the foreground, it dies. Pick one method.
|
||||
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.
|
||||
|
||||
### Method A — `screen` (simplest)
|
||||
### Method A — `streamd serve start` (recommended)
|
||||
|
||||
Built into the binary. Reads `streamd.yaml`, writes pid + log, safe to close SSH:
|
||||
|
||||
```bash
|
||||
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](#10-stopping--upgrading)).
|
||||
|
||||
Optional thin wrappers (same commands) if you already curl’d them:
|
||||
|
||||
```bash
|
||||
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`):
|
||||
|
||||
```bash
|
||||
nohup ./streamd agent run --config agent.yaml >agent.log 2>&1 &
|
||||
# or: ./streamd-bg.sh start-agent
|
||||
```
|
||||
|
||||
### Method B — `screen`
|
||||
|
||||
```bash
|
||||
sudo apt-get update && sudo apt-get install -y screen # Debian/Ubuntu
|
||||
|
|
@ -308,7 +381,7 @@ Start streamd inside a named screen:
|
|||
```bash
|
||||
cd ~/null-drm
|
||||
screen -S streamd
|
||||
./streamd serve --bind 0.0.0.0:8083 --data .cache/streamd
|
||||
./streamd serve --bind 0.0.0.0:8083
|
||||
```
|
||||
|
||||
Detach without killing it: press **`Ctrl+A`**, then **`D`**.
|
||||
|
|
@ -330,36 +403,17 @@ cd ~/null-drm
|
|||
|
||||
List sessions: `screen -ls`
|
||||
|
||||
### Method B — `tmux` (same idea)
|
||||
### Method C — `tmux` (same idea)
|
||||
|
||||
```bash
|
||||
sudo apt-get install -y tmux
|
||||
cd ~/null-drm
|
||||
tmux new -s streamd
|
||||
./streamd serve --bind 0.0.0.0:8083 --data .cache/streamd
|
||||
./streamd serve --bind 0.0.0.0:8083
|
||||
# Detach: Ctrl+B then D
|
||||
# Reattach: tmux attach -t streamd
|
||||
```
|
||||
|
||||
### Method C — `nohup` (one-liner, no session to reattach)
|
||||
|
||||
```bash
|
||||
cd ~/null-drm
|
||||
nohup ./streamd serve --bind 0.0.0.0:8083 --data .cache/streamd > streamd.log 2>&1 &
|
||||
echo $! > streamd.pid
|
||||
|
||||
# optional agent
|
||||
nohup ./streamd agent run --config agent.yaml > agent.log 2>&1 &
|
||||
echo $! > agent.pid
|
||||
```
|
||||
|
||||
Stop later:
|
||||
|
||||
```bash
|
||||
kill "$(cat streamd.pid)"
|
||||
kill "$(cat agent.pid)"
|
||||
```
|
||||
|
||||
### Method D — systemd (survives reboot — recommended for a real server)
|
||||
|
||||
Create a user unit (no root binary needed). Paths assume install in `/home/ubuntu/null-drm`
|
||||
|
|
@ -376,7 +430,8 @@ Wants=network-online.target
|
|||
Type=simple
|
||||
User=ubuntu
|
||||
WorkingDirectory=/home/ubuntu/null-drm
|
||||
ExecStart=/home/ubuntu/null-drm/streamd serve --bind 0.0.0.0:8083 --data /home/ubuntu/null-drm/.cache/streamd
|
||||
# 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):
|
||||
|
|
@ -424,7 +479,75 @@ Same pattern with `streamd-agent` for the agent unit.
|
|||
|
||||
---
|
||||
|
||||
## 7. Quick “am I done?” checklist
|
||||
## 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
|
||||
|
||||
```bash
|
||||
# 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.
|
||||
|
||||
### 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
|
||||
|
||||
```bash
|
||||
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
|
||||
|
||||
```bash
|
||||
cd ~/null-drm
|
||||
|
|
@ -447,7 +570,7 @@ Play the m3u8 in VLC / ffplay / any HLS player using the server IP URL.
|
|||
|
||||
---
|
||||
|
||||
## 8. Common problems
|
||||
## 9. Common problems
|
||||
|
||||
| Symptom | Fix |
|
||||
|---|---|
|
||||
|
|
@ -455,30 +578,89 @@ Play the m3u8 in VLC / ffplay / any HLS player using the server IP URL.
|
|||
| 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 screen/tmux/nohup/systemd from §6 |
|
||||
| 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 |
|
||||
|
||||
---
|
||||
|
||||
## 9. Stopping / upgrading
|
||||
## 10. Stopping / upgrading
|
||||
|
||||
Stop a foreground or screen session with `Ctrl+C` inside that session.
|
||||
|
||||
Upgrade:
|
||||
Built into the binary — one command stops, downloads, archives the old binary
|
||||
under `./old/`, and restarts:
|
||||
|
||||
```bash
|
||||
cd ~/null-drm
|
||||
# stop streamd first (systemctl stop streamd / kill / Ctrl+C)
|
||||
curl -fL -o streamd.new \
|
||||
"https://git.nulldrm.com/nulldrm/Null-DRM-Official/releases/download/stable/streamd-linux-amd64"
|
||||
chmod +x streamd.new
|
||||
mv streamd streamd.bak
|
||||
mv streamd.new streamd
|
||||
# start again
|
||||
./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
|
||||
```
|
||||
|
||||
Back up `.cache/streamd/streamd.db` before big upgrades.
|
||||
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:
|
||||
|
||||
```text
|
||||
~/null-drm/
|
||||
streamd
|
||||
streamd.yaml
|
||||
old/
|
||||
streamd.20261010T153012Z
|
||||
streamd.20261012T091500Z
|
||||
.cache/streamd/
|
||||
```
|
||||
|
||||
Roll back:
|
||||
|
||||
```bash
|
||||
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
|
||||
|
||||
```bash
|
||||
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
|
||||
|
||||
```bash
|
||||
sudo systemctl stop streamd
|
||||
./streamd serve update --no-restart
|
||||
sudo systemctl start streamd
|
||||
sudo systemctl status streamd
|
||||
```
|
||||
|
||||
### Optional shell wrappers
|
||||
|
||||
```bash
|
||||
./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.
|
||||
|
||||
---
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue