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 ¶
- Variables
- func ClearHTTPHandler(name string, h http.Handler)
- func GetHTTPHandler(name string) http.Handler
- func RegisterApp(name string, fn AppFunc)
- func RegisterHTTPHandler(name string, h http.Handler)
- type AppFunc
- type AppLauncher
- func (l *AppLauncher) AppState(name string) (*appserver.AppState, bool)
- func (l *AppLauncher) AppStates() []*appserver.AppState
- func (l *AppLauncher) AutoStart(envMap EnvMap) error
- func (l *AppLauncher) DeregisterApp(procKey appcommon.ProcKey) error
- func (l *AppLauncher) KillApp(name string) error
- func (l *AppLauncher) RegisterApp(procConf appcommon.ProcConfig) (appcommon.ProcKey, error)
- func (l *AppLauncher) ResetConfig(conf AppLauncherConfig)
- func (l *AppLauncher) RestartApp(name, binary string) error
- func (l *AppLauncher) StartApp(cmd string, args, envs []string) error
- func (l *AppLauncher) StartAppWithMode(cmd string, args, envs []string, launcherMode string) error
- func (l *AppLauncher) StopApp(name string) (*appserver.Proc, error)
- type AppLauncherConfig
- type EnvMaker
- type EnvMap
Constants ¶
This section is empty.
Variables ¶
var ( ErrAppNotFound = errors.New("app not found") ErrAppNotRunning = errors.New("app not running") )
Launcher associated errors.
Functions ¶
func ClearHTTPHandler ¶
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 ¶
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 ¶
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 ¶
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 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.