startup

package
v0.1.0-alpha.83 Latest Latest
Warning

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

Go to latest
Published: Nov 9, 2026 License: GPL-3.0 Imports: 20 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package startup owns local launch coordination and bounded, credential-free startup diagnostics. It does not depend on the datastore, HTTP API or motion.

Index

Constants

This section is empty.

Variables

View Source
var ErrRunning = errors.New("MagicHandy is already starting or running for this data directory")

ErrRunning means another process holds this profile's operating-system lock.

Functions

func SavePortHint

func SavePortHint(dataDir string, hint PortHint) error

SavePortHint never changes the configured preferred address.

Types

type Attempt

type Attempt struct {
	Listener   string `json:"listener"`
	Port       int    `json:"port"`
	ErrorCode  string `json:"error_code,omitempty"`
	NativeCode int    `json:"native_code,omitempty"`
}

Attempt describes a bind without retaining an address, path, raw error or key.

type Existing

type Existing struct {
	PID                int    `json:"pid"`
	ID                 string `json:"instance_id"`
	URL                string `json:"url"`
	RemoteURL          string `json:"remote_url,omitempty"`
	PreferredURL       string `json:"preferred_url,omitempty"`
	PreferredRemoteURL string `json:"preferred_remote_url,omitempty"`
}

Existing is the public, verified part of a running instance record.

func FindExisting

func FindExisting(ctx context.Context, dataDir string) (Existing, error)

FindExisting waits for an instance already holding the profile lock. Redirects and environment proxies are disabled; the token itself is never transmitted.

type Instance

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

Instance holds the profile lock until all application workers have stopped. The lock file is never unlinked: replacing it could allow two lock owners.

func Acquire

func Acquire(dataDir string) (*Instance, error)

Acquire creates no datastore or workers. OS locks are released on crashes.

func (*Instance) Close

func (i *Instance) Close()

Close removes readiness before releasing the profile lock. Call after teardown.

func (*Instance) Handler

func (i *Instance) Handler(next http.Handler) http.Handler

Handler proves the local process's identity without exposing the private token to a potentially unrelated service occupying a stale endpoint. The deliberately public response contains no account, settings or device state.

func (*Instance) Publish

func (i *Instance) Publish(appURL, remoteURL string) error

Publish exposes only prepared endpoints. A caller also has to complete a fresh challenge through the serving socket before accepting the record.

func (*Instance) PublishWithPreference

func (i *Instance) PublishWithPreference(appURL, remoteURL, preferredURL, preferredRemoteURL string) error

PublishWithPreference records user intent separately from the bound endpoint.

type PortHint

type PortHint struct {
	Preference string `json:"preference"`
	Main       int    `json:"main"`
	Remote     int    `json:"remote"`
}

PortHint preserves a successful local origin when the preferred port was unavailable. Preference keys prevent a changed configuration inheriting it.

func ReadPortHint

func ReadPortHint(dataDir, preference string) PortHint

ReadPortHint treats missing or malformed hints as an ordinary first launch.

type Recorder

type Recorder struct {
	Report Report
	// contains filtered or unexported fields
}

Recorder is used only by the startup goroutine. Readers use atomic disk files.

func NewRecorder

func NewRecorder(dataDir, version, commit string) *Recorder

NewRecorder does not open the datastore or require a writable data directory.

func (*Recorder) Bind

func (r *Recorder) Bind(listener, address string, err error) bool

Bind records each attempt and returns whether a different port could help.

func (*Recorder) Finish

func (r *Recorder) Finish(err error) (string, error)

Finish writes bounded documents. A storage failure falls back to a private temporary directory; the returned path can still be shown in the console.

type Report

type Report struct {
	SchemaVersion int       `json:"schema_version"`
	AppVersion    string    `json:"app_version"`
	Commit        string    `json:"commit"`
	Platform      string    `json:"platform"`
	StartedAt     time.Time `json:"started_at"`
	FinishedAt    time.Time `json:"finished_at"`
	Stage         string    `json:"stage"`
	Outcome       string    `json:"outcome"`
	Policy        string    `json:"port_policy,omitempty"`
	ErrorCode     string    `json:"error_code,omitempty"`
	NativeCode    int       `json:"native_code,omitempty"`
	Attempts      []Attempt `json:"attempts"`
}

Report is an allowlist of startup facts, safe to retain before the API exists.

type Reports

type Reports struct {
	Current      *Report `json:"current"`
	LastFailure  *Report `json:"last_failure"`
	LastRecovery *Report `json:"last_recovery"`
}

Reports keeps the latest failure and recovery across ordinary clean launches.

func ReadReports

func ReadReports(dataDir string) Reports

ReadReports excludes the instance record and its private identity token.

Jump to

Keyboard shortcuts

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