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:
404errordeveloper 2026-10-10 18:05:51 +02:00
parent da8e1123ec
commit 8fc7e4c0b8
57 changed files with 4031 additions and 257 deletions

View file

@ -92,7 +92,6 @@ func Ensure(root string) (created []string, err error) {
}
// If streamd is not already under bin/, copy it there for 1:1 layout.
// Also keep a drm.exe compat copy for one release when missing.
if err := ensureBinHost(root); err != nil {
return created, err
}
@ -105,10 +104,7 @@ func ensureBinHost(root string) error {
return nil
}
exe, _ = filepath.EvalSymlinks(exe)
if err := copyExeIfMissing(exe, filepath.Join(root, "bin", "streamd.exe")); err != nil {
return err
}
return copyExeIfMissing(exe, filepath.Join(root, "bin", "drm.exe"))
return copyExeIfMissing(exe, filepath.Join(root, "bin", "streamd.exe"))
}
func copyExeIfMissing(src, dest string) error {

View file

@ -21,7 +21,8 @@ import (
)
// Dir returns the directory holding a module's values.
// Prefers the active modules dir (see modhost / --modules-dir); falls back to
// Prefers the active modules dir (see modhost / --modules-dir); then the
// directory beside a panel/release binary (<mod>/.bin/<name>); then
// apps/modules/<name>/ for older checkouts.
func Dir(name string) string {
preferred := filepath.Join(modhost.ModulesDir(""), name)
@ -31,6 +32,9 @@ func Dir(name string) string {
if modhost.ModulesDirOverride() != "" {
return preferred
}
if beside := dirBesideExecutable(name); beside != "" {
return beside
}
root := repo.Root()
if _, err := os.Stat(filepath.Join(root, "modules")); err == nil {
return filepath.Join(root, "modules", name)
@ -38,6 +42,43 @@ func Dir(name string) string {
return filepath.Join(root, "apps", "modules", name)
}
// dirBesideExecutable finds module.yaml next to a panel/release binary layout:
// <modDir>/.bin/<name>[.exe]
// <modDir>/.bin/<goos>-<goarch>/<name>[.exe]
func dirBesideExecutable(name string) string {
exe, err := os.Executable()
if err != nil {
return ""
}
if resolved, err := filepath.EvalSymlinks(exe); err == nil {
exe = resolved
}
base := strings.TrimSuffix(filepath.Base(exe), ".exe")
if !strings.EqualFold(base, name) {
return ""
}
binDir := filepath.Dir(exe)
candidates := []string{}
if strings.EqualFold(filepath.Base(binDir), ".bin") {
candidates = append(candidates, filepath.Dir(binDir))
}
parent := filepath.Dir(binDir)
if strings.EqualFold(filepath.Base(parent), ".bin") {
candidates = append(candidates, filepath.Dir(parent))
}
for _, dir := range candidates {
if fileExists(filepath.Join(dir, "module.yaml")) || fileExists(filepath.Join(dir, "module-publish.yaml")) {
return dir
}
}
return ""
}
func fileExists(p string) bool {
st, err := os.Stat(p)
return err == nil && !st.IsDir()
}
// Path returns the preferred values file path (module.yaml).
func Path(name string) string {
return filepath.Join(Dir(name), "module.yaml")

View file

@ -9,9 +9,39 @@ import (
"strings"
)
// prepareModuleCmd sets STREAMD_MODULES_DIR so child module binaries load
// panel-store module.yaml. Module builds that call EffectiveModulesDir (or
// ApplyEnvModulesDir) honour this; /api/apps also falls back to parsing the
// panel module.yaml when describe returns no channels.
func prepareModuleCmd(cmd *exec.Cmd) {
ov := ModulesDirOverride()
if ov == "" {
return
}
cmd.Env = append(withoutEnvKeys(os.Environ(), "STREAMD_MODULES_DIR", "DRM_MODULES_DIR"),
"STREAMD_MODULES_DIR="+ov)
}
func withoutEnvKeys(env []string, keys ...string) []string {
drop := map[string]struct{}{}
for _, k := range keys {
drop[strings.ToUpper(k)] = struct{}{}
}
out := make([]string, 0, len(env))
for _, e := range env {
key, _, _ := strings.Cut(e, "=")
if _, skip := drop[strings.ToUpper(key)]; skip {
continue
}
out = append(out, e)
}
return out
}
// Run executes the module binary with args, inheriting stdout/stderr.
func Run(bin string, args ...string) error {
cmd := exec.Command(bin, args...)
prepareModuleCmd(cmd)
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
cmd.Stdin = os.Stdin
@ -24,6 +54,7 @@ func Run(bin string, args ...string) error {
// RunOutput executes the module binary and returns combined stdout.
func RunOutput(bin string, args ...string) (string, error) {
cmd := exec.Command(bin, args...)
prepareModuleCmd(cmd)
var stdout, stderr bytes.Buffer
cmd.Stdout = &stdout
cmd.Stderr = &stderr

View file

@ -0,0 +1,31 @@
package modhost
import (
"os"
"os/exec"
"path/filepath"
"testing"
)
func TestPrepareModuleCmdSetsEnv(t *testing.T) {
t.Cleanup(func() { _ = SetModulesDir("") })
ov := filepath.Join(t.TempDir(), "modules")
if err := os.MkdirAll(ov, 0o755); err != nil {
t.Fatal(err)
}
if err := SetModulesDir(ov); err != nil {
t.Fatal(err)
}
cmd := exec.Command("true")
prepareModuleCmd(cmd)
found := false
for _, e := range cmd.Env {
if e == "STREAMD_MODULES_DIR="+ov {
found = true
break
}
}
if !found {
t.Fatalf("STREAMD_MODULES_DIR missing in env: %v", cmd.Env)
}
}

View file

@ -3,6 +3,7 @@ package modhost
import (
"os"
"path/filepath"
"strings"
"sync"
"streamd/repo"
@ -37,12 +38,32 @@ func ModulesDirOverride() string {
return modulesDirOV
}
// envModulesDir returns STREAMD_MODULES_DIR (preferred) or DRM_MODULES_DIR.
func envModulesDir() string {
v := strings.TrimSpace(os.Getenv("STREAMD_MODULES_DIR"))
if v == "" {
v = strings.TrimSpace(os.Getenv("DRM_MODULES_DIR"))
}
if v == "" {
return ""
}
if abs, err := filepath.Abs(v); err == nil {
return abs
}
return v
}
// EffectiveModulesDir is the directory that Discover/Open scan.
// Prefer --modules-dir / STREAMD_MODULES_DIR / DRM_MODULES_DIR; else <root>/modules.
// Prefer --modules-dir, then STREAMD_MODULES_DIR / DRM_MODULES_DIR, else <root>/modules.
// Module binaries read the env here directly so they honour the panel store even
// when they never call ApplyEnvModulesDir.
func EffectiveModulesDir(root string) string {
if ov := ModulesDirOverride(); ov != "" {
return ov
}
if v := envModulesDir(); v != "" {
return v
}
if root == "" {
root = repo.Root()
}
@ -55,10 +76,7 @@ func ApplyEnvModulesDir() error {
if ModulesDirOverride() != "" {
return nil
}
v := os.Getenv("STREAMD_MODULES_DIR")
if v == "" {
v = os.Getenv("DRM_MODULES_DIR")
}
v := envModulesDir()
if v == "" {
return nil
}

View file

@ -0,0 +1,39 @@
package modhost
import (
"os"
"path/filepath"
"testing"
)
func TestEffectiveModulesDirEnv(t *testing.T) {
t.Cleanup(func() {
_ = SetModulesDir("")
_ = os.Unsetenv("STREAMD_MODULES_DIR")
_ = os.Unsetenv("DRM_MODULES_DIR")
})
_ = SetModulesDir("")
_ = os.Unsetenv("STREAMD_MODULES_DIR")
_ = os.Unsetenv("DRM_MODULES_DIR")
dir := t.TempDir()
t.Setenv("STREAMD_MODULES_DIR", dir)
got := EffectiveModulesDir("")
want, _ := filepath.Abs(dir)
if got != want {
t.Fatalf("env modules dir: got %q want %q", got, want)
}
override := filepath.Join(t.TempDir(), "override")
if err := os.MkdirAll(override, 0o755); err != nil {
t.Fatal(err)
}
if err := SetModulesDir(override); err != nil {
t.Fatal(err)
}
got = EffectiveModulesDir("")
want, _ = filepath.Abs(override)
if got != want {
t.Fatalf("flag overrides env: got %q want %q", got, want)
}
}