Documentation
¶
Overview ¶
Package demo owns the disposable installed local measurement.
Index ¶
- Constants
- Variables
- func BootstrapFresh(ctx context.Context, role SchemaRole, path string) error
- func CheckSchema(ctx context.Context, role SchemaRole, path string) error
- func DefaultLocalStateDir() (string, error)
- func DispatcherConfiguration(version, database string) map[string]any
- func DispatcherUp(ctx context.Context, assets Assets, options RoleOptions) error
- func ExecutorConfiguration(version, executorID, database string, dispatcher readiness.Record) map[string]any
- func ExecutorUp(ctx context.Context, assets Assets, options RoleOptions) error
- func FileNames(info fs.FileInfo) (uint64, bool)
- func PrepareRoleDatabase(ctx context.Context, role SchemaRole, dir string) (path string, created bool, err error)
- func ReadReadyRecord(path string, pid int, executorID string) (readiness.Record, error)
- func RoleDatabase(dir string, role SchemaRole) string
- func Up(ctx context.Context, assets Assets, options LocalOptions) error
- func ValidateControlAddress(address string) error
- func WriteConfig(path string, config map[string]any) error
- type Assets
- type Child
- type ChildSpec
- type LocalEnvironment
- type LocalOptions
- type Manifest
- type Result
- type RoleEnvironment
- type RoleOptions
- type RoleState
- type SchemaRole
Constants ¶
const OpenWithoutWaiting = syscall.O_NONBLOCK
OpenWithoutWaiting is the open flag that keeps opening a named pipe from waiting until somebody opens the other end. A privileged command that opens what it finds in a directory another account writes needs it, or that account can stop the command indefinitely by leaving a pipe there.
Variables ¶
var ErrForcedKill = errors.New("demo child required forced termination")
ErrForcedKill distinguishes cleanup that required SIGKILL from graceful exit.
Functions ¶
func BootstrapFresh ¶
func BootstrapFresh(ctx context.Context, role SchemaRole, path string) error
BootstrapFresh applies the canonical migrations to a new, private database. The caller must own the mode-0700 parent and keep it exclusively under its control until this function returns. Existing databases are never upgraded.
func CheckSchema ¶
func CheckSchema(ctx context.Context, role SchemaRole, path string) error
CheckSchema verifies an existing database against the schema versions this package's services support. Local services never upgrade a database in place, so an unsupported one is reported instead of being migrated.
func DefaultLocalStateDir ¶
DefaultLocalStateDir follows the XDG state convention without depending on the current working directory.
func DispatcherConfiguration ¶
DispatcherConfiguration returns the generated dispatcher configuration for a database path. Callers may override the server ports before writing it.
func DispatcherUp ¶
func DispatcherUp(ctx context.Context, assets Assets, options RoleOptions) error
func ExecutorConfiguration ¶
func ExecutorConfiguration(version, executorID, database string, dispatcher readiness.Record) map[string]any
ExecutorConfiguration returns the generated executor configuration for one executor identity, database and dispatcher control record.
func ExecutorUp ¶
func ExecutorUp(ctx context.Context, assets Assets, options RoleOptions) error
func FileNames ¶
FileNames reports how many names a file has. A regular file with more than one is reachable under a name this caller never created and may not be able to see, so ownership applied to it is applied to that name too.
func PrepareRoleDatabase ¶
func PrepareRoleDatabase(ctx context.Context, role SchemaRole, dir string) (path string, created bool, err error)
PrepareRoleDatabase creates the role's database on first use and verifies an existing one against the schema versions this build serves. It never migrates: an unsupported database is reported with the action to take. It reports whether this call is the one that created the database. The caller owns the mode-0700 parent directory for the whole call.
Whether creating is allowed is the bootstrap's own decision, not a guess made here: it requires a mode-0700 parent this administrator owns, which is a directory an installation has just made and never one it handed to the service account when it last finished. So an installation interrupted before its database existed can be completed by the next one, a finished directory can have nothing created in it, and no account that could replace the name in between has the directory to do it in.
func ReadReadyRecord ¶
ReadReadyRecord reads one published readiness record and checks it against the process that was supposed to publish it. The record is evidence that the daemon reached its own ready point: an existing process, or a service manager that merely created one, proves nothing on its own. A missing record is reported as os.ErrNotExist so a caller can keep waiting for it.
func RoleDatabase ¶
func RoleDatabase(dir string, role SchemaRole) string
RoleDatabase names the database file a role keeps in its state directory.
func Up ¶
func Up(ctx context.Context, assets Assets, options LocalOptions) error
Up runs an installed loopback environment until cancellation. Databases and identity survive clean shutdown; environment.json exists only while ready. A canceled context means a normal stop, provided child cleanup succeeds.
func ValidateControlAddress ¶
ValidateControlAddress accepts the literal-loopback host:port spelling the generated configurations use for the local control plane.
Types ¶
type Assets ¶
func ResolveAssets ¶
ResolveAssets follows the entry-point symlink once, then verifies the exact installed payload. Neither PATH nor the current directory supplies assets.
type Child ¶
type Child struct {
// contains filtered or unexported fields
}
Child owns one process group and exactly one cmd.Wait invocation. Closing done publishes waitErr and also joins os/exec's output-copy goroutines.
func StartChild ¶
func (*Child) CleanupComplete ¶
CleanupComplete proves both the controller and direct-child reaper joined, and that the entire tracked process group disappeared. Cache observed group removal so a future unrelated reuse of this numeric PGID cannot change it.
type LocalEnvironment ¶
type LocalEnvironment struct {
State string `json:"state"`
Endpoint string `json:"endpoint"`
ExecutorID string `json:"executor_id"`
StateDir string `json:"state_dir"`
}
LocalEnvironment describes the currently running local services.
type LocalOptions ¶
type LocalOptions struct {
StateDir string
Port int
Ready func(LocalEnvironment) error
}
type Result ¶
type RoleEnvironment ¶
type RoleEnvironment struct {
State string `json:"state"`
Role string `json:"role"`
Name string `json:"name"`
Endpoint string `json:"endpoint"`
GRPCAddress string `json:"grpc_address,omitempty"`
YamuxAddress string `json:"yamux_address,omitempty"`
ExecutorID string `json:"executor_id,omitempty"`
StateDir string `json:"state_dir"`
}
RoleEnvironment describes one independently running local service.
type RoleOptions ¶
type RoleOptions struct {
Name, StateDir string
Port, GRPCPort int
Dispatcher connections.Profile
Ready func(RoleEnvironment) error
}
type RoleState ¶
type RoleState struct {
SchemaVersion int `json:"schema_version"`
Version string `json:"version"`
SourceSHA string `json:"source_sha"`
ExecutorID string `json:"executor_id"`
Role SchemaRole `json:"role"`
}
RoleState is the persistent identity of one managed role directory. It pins the installed version that created the directory, so a payload the databases were never served by cannot silently adopt them.
func EnsureRoleState ¶
func EnsureRoleState(dir string, role SchemaRole, manifest Manifest) (RoleState, error)
EnsureRoleState reads, or on first use creates, the persistent identity of a role state directory. The caller owns the mode-0700 directory and keeps it under its own control for the duration of the call.
type SchemaRole ¶
type SchemaRole string
const ( DispatcherSchema SchemaRole = "dispatcher" ExecutorSchema SchemaRole = "executor" )