startupscript

package
v0.25.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 25, 2026 License: MIT Imports: 13 Imported by: 0

Documentation

Overview

Package startupscript runs an admin-defined shell script when the server boots. Use case: spawn a tunnel (ngrok / cloudflared) so the local HTTP port stays unexposed to the LAN — the admin configures the command via /admin/variables (startup_script + startup_script_enabled) and the server fires it once Bootstrap finishes.

Lifetime is tied to the caller's context: when the context cancels (server stop / tray quit) the subprocess and every child it spawned receive a kill signal via the platform's process-group mechanism (Setpgid + kill -pgid on Unix, Job Object kill-on-close on Windows). Without this, a backgrounded `ngrok &` survives wick shutdown as an orphan re-parented to init — leaking tunnels and accumulating zombies on every restart.

Output (stdout + stderr) is appended to ~/.<appName>/logs/startup-script-YYYY-MM-DD.log.

Multi-line scripts run sequentially in one shell process, exactly like a `.sh` / `.ps1` file. Long-running foreground commands block subsequent lines — use `&` (Unix) or `Start-Process` (Windows) for parallel daemons. Edits to the script row only take effect on next server boot.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Run

func Run(ctx context.Context, appName, script string) error

Run spawns the script in a fresh shell, waits for context cancel, then kills the subprocess plus every descendant via the platform's process-group mechanism. Blocking call — callers spawn it in a goroutine. Returns immediately with nil when script is empty or only whitespace.

appName scopes the log file location (~/.<appName>/logs/...). Pass the same string used elsewhere (APP_NAME env / userconfig.Dir input) so logs land next to server/worker/app logs.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL