Help us shape the future of Go! Take the 2026 Go Developer Survey

launcher

package
v1.3.98 Latest Latest
Warning

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

Go to latest
Published: Sep 30, 2026 License: AGPL-3.0 Imports: 22 Imported by: 1

Documentation

Overview

Package launcher pkg/app/launcher/launcher.go c2-vis-appsvc

Package launcher pkg/app/launcher/proc_env_native.go c2-app-launcher

Package launcher pkg/app/launcher/registry.go c2-vis-appsvc

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrAppNotFound   = errors.New("app not found")
	ErrAppNotRunning = errors.New("app not running")
)

Launcher associated errors.

Functions

func ClearHTTPHandler

func ClearHTTPHandler(name string, h http.Handler)

ClearHTTPHandler removes name's entry only if it currently holds h.

This is what a shutting-down app should call instead of RegisterHTTPHandler(name, nil). An app restart re-registers before the old instance finishes unwinding, so a plain delete-by-name races: the old instance's cleanup can land after the new one has published, taking a live handler out of the registry and leaving the consumer with nothing to serve. Compare-and-delete under the write lock closes that window — a Get followed by a conditional Register would not, since the two are separate acquisitions.

func GetHTTPHandler

func GetHTTPHandler(name string) http.Handler

GetHTTPHandler returns the in-process HTTP handler an internal app published, or nil if none is registered (the app runs externally on its own port).

func RegisterApp

func RegisterApp(name string, fn AppFunc)

RegisterApp registers an app function by name.

Registration is mutex-guarded and idempotent. Guarded because module inits run concurrently (visorinit.InitConcurrent), so several embedded-app modules call this in parallel — an unsynchronized map write there is a data race that can fatally crash the process. Idempotent because a visor Resume re-runs the whole module-init graph after Suspend, so each embedded app re-registers its (same, deterministic) func; the old hard panic on a duplicate name turned Resume into a half-initialized, still-"suspended" state (dmsg_pty/dmsgweb/skynetweb panicked on their already-registered names). Re-registering overwrites — the same overwrite-on-re-register semantics RegisterHTTPHandler below already uses.

func RegisterHTTPHandler

func RegisterHTTPHandler(name string, h http.Handler)

RegisterHTTPHandler publishes an internal app's in-process HTTP handler. It overwrites any previous handler for the same name (an app restart re-registers); passing nil clears the entry (call on shutdown).

Types

type AppFunc

type AppFunc = appcommon.AppFunc

AppFunc is an alias for the app function type defined in appcommon.

func GetApp

func GetApp(name string) (AppFunc, bool)

GetApp returns the app function for the given name, or nil if not found.

type AppLauncher

type AppLauncher struct {
	// contains filtered or unexported fields
}

AppLauncher is responsible for launching and keeping track of app states.

func NewLauncher

func NewLauncher(log logrus.FieldLogger, conf AppLauncherConfig, dmsgC *dmsg.Client, r router.Router, procM appserver.ProcManager) (*AppLauncher, error)

NewLauncher creates a new launcher.

func (*AppLauncher) AppState

func (l *AppLauncher) AppState(name string) (*appserver.AppState, bool)

AppState returns a single app state of given name.

func (*AppLauncher) AppStates

func (l *AppLauncher) AppStates() []*appserver.AppState

AppStates returns list of AppStates for all registered apps.

func (*AppLauncher) AutoStart

func (l *AppLauncher) AutoStart(envMap EnvMap) error

AutoStart auto-starts marked apps.

func (*AppLauncher) DeregisterApp

func (l *AppLauncher) DeregisterApp(procKey appcommon.ProcKey) error

DeregisterApp de registers the proc used by an external.

func (*AppLauncher) KillApp

func (l *AppLauncher) KillApp(name string) error

KillApp stop an app, by its name | We use it on stop apps during its running steps by cli.

func (*AppLauncher) RegisterApp

func (l *AppLauncher) RegisterApp(procConf appcommon.ProcConfig) (appcommon.ProcKey, error)

RegisterApp registers a proc for an external app to use.

func (*AppLauncher) ResetConfig

func (l *AppLauncher) ResetConfig(conf AppLauncherConfig)

ResetConfig resets the launcher config.

func (*AppLauncher) RestartApp

func (l *AppLauncher) RestartApp(name, binary string) error

RestartApp restarts a running app.

func (*AppLauncher) StartApp

func (l *AppLauncher) StartApp(cmd string, args, envs []string) error

StartApp starts cmd with given args and env. If 'args' is nil, default args will be used.

func (*AppLauncher) StartAppWithMode

func (l *AppLauncher) StartAppWithMode(cmd string, args, envs []string, launcherMode string) error

StartAppWithMode starts cmd with given args, env, and launcher mode override. launcherMode can be "internal", "external", or "" for default behavior.

func (*AppLauncher) StopApp

func (l *AppLauncher) StopApp(name string) (*appserver.Proc, error)

StopApp stops running app.

For apps with RestartPolicy=Always, the stop is followed immediately by an auto-restart — operator-initiated stop is a no-op semantically on critical apps (pty, etc.) so a stray click can't lock an operator out of remote management. The path to actually disable an Always-policy app is to remove its config entry and restart the visor. RestartPolicy enforcement for crash recovery (Always + OnFailure) lives in watchAndRestart; that watcher can't reliably distinguish operator-initiated stop from a clean exit because procM.Stop de-registers the proc before Wait observes the exit, surfacing ErrNoSuchApp in both paths — so we handle Always here at the source of truth instead.

type AppLauncherConfig

type AppLauncherConfig struct {
	VisorPK       cipher.PubKey
	Apps          []appserver.AppConfig
	ServerAddr    string
	BinPath       string
	LocalPath     string
	DisplayNodeIP bool
}

AppLauncherConfig configures the launcher.

type EnvMaker

type EnvMaker func() ([]string, error)

EnvMaker makes a list of environment variables with their values set It is used to let other code to decide how environment variables should be built

type EnvMap

type EnvMap map[string]EnvMaker

EnvMap is a mapping from application name to environment maker function

Jump to

Keyboard shortcuts

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