- 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
84 lines
1.9 KiB
Go
84 lines
1.9 KiB
Go
package modhost
|
|
|
|
import (
|
|
"os"
|
|
"path/filepath"
|
|
"strings"
|
|
"sync"
|
|
|
|
"streamd/repo"
|
|
)
|
|
|
|
var (
|
|
rootMu sync.RWMutex
|
|
modulesDirOV string // absolute path override for the modules directory
|
|
)
|
|
|
|
// SetModulesDir overrides where providers are discovered (streamd --modules-dir).
|
|
// Empty clears the override. Relative paths are resolved against the process cwd.
|
|
func SetModulesDir(dir string) error {
|
|
rootMu.Lock()
|
|
defer rootMu.Unlock()
|
|
if dir == "" {
|
|
modulesDirOV = ""
|
|
return nil
|
|
}
|
|
abs, err := filepath.Abs(dir)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
modulesDirOV = abs
|
|
return nil
|
|
}
|
|
|
|
// ModulesDirOverride returns the --modules-dir override, or "".
|
|
func ModulesDirOverride() string {
|
|
rootMu.RLock()
|
|
defer rootMu.RUnlock()
|
|
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, 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()
|
|
}
|
|
return filepath.Join(root, "modules")
|
|
}
|
|
|
|
// ApplyEnvModulesDir sets the override from STREAMD_MODULES_DIR (preferred) or
|
|
// DRM_MODULES_DIR when no flag was set.
|
|
func ApplyEnvModulesDir() error {
|
|
if ModulesDirOverride() != "" {
|
|
return nil
|
|
}
|
|
v := envModulesDir()
|
|
if v == "" {
|
|
return nil
|
|
}
|
|
return SetModulesDir(v)
|
|
}
|