outboard

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Mar 10, 2026 License: Apache-2.0 Imports: 22 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func WriteConfig

func WriteConfig(path string, cfg *Config) error

WriteConfig writes an outboard config to the given path atomically. It uses a temp file and rename to ensure readers never see partial data.

Types

type Config

type Config struct {
	Token      string `json:"token"`
	FIFOStdout string `json:"fifo_stdout"`
	FIFOStderr string `json:"fifo_stderr"`
	PID        int    `json:"pid,omitempty"`
	RPCAddr    string `json:"rpc_addr,omitempty"`
	Ready      bool   `json:"ready,omitempty"`
}

Config is the shared configuration file format between the connector (parent) and the outboard process (child). The connector writes it before starting the process; the process reads it on startup and writes back its RPC address, PID, and ready flag.

func ReadConfig

func ReadConfig(path string) (*Config, error)

ReadConfig reads an outboard config from the given path.

type Connector

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

Connector manages the lifecycle of an outboard process from the parent side. It handles starting, monitoring, restarting, and RPC connection to the child.

func NewConnector

func NewConnector(log *slog.Logger, cfg ConnectorConfig) *Connector

NewConnector creates a new Connector for managing an outboard process.

func (*Connector) Close

func (c *Connector) Close() error

Close stops the process and cleans up resources.

func (*Connector) ConnectInterface

func (c *Connector) ConnectInterface(name string) (*rpc.NetworkClient, error)

ConnectInterface connects to an additional RPC interface exposed by the outboard process.

func (*Connector) ControlClient

func (c *Connector) ControlClient() *outboard_v1alpha.OutboardControlClient

ControlClient returns the OutboardControl RPC client.

func (*Connector) Detach

func (c *Connector) Detach() error

Detach disconnects from the outboard process without stopping it. Call this during restart - the process keeps running and can be reconnected later.

func (*Connector) IsRunning

func (c *Connector) IsRunning() bool

IsRunning returns whether the outboard process is currently running.

func (*Connector) PID

func (c *Connector) PID() (int, error)

PID returns the PID of the running outboard process.

func (*Connector) RPCState

func (c *Connector) RPCState() *rpc.State

RPCState returns the parent-side RPC state for connecting to additional interfaces exposed by the outboard process.

func (*Connector) Reconnect

func (c *Connector) Reconnect(ctx context.Context) error

Reconnect attempts to connect to an existing outboard process. Returns error if no process is running or reconnection fails.

func (*Connector) Start

func (c *Connector) Start(ctx context.Context) error

Start starts the outboard process and waits for it to become ready.

func (*Connector) StartOrReconnect

func (c *Connector) StartOrReconnect(ctx context.Context) error

StartOrReconnect tries to reconnect to an existing outboard process first, falling back to starting a fresh process if reconnection fails.

func (*Connector) Stop

func (c *Connector) Stop(ctx context.Context) error

Stop gracefully stops the outboard process.

type ConnectorConfig

type ConnectorConfig struct {
	Name          string
	BinaryPath    string
	Args          []string
	Env           []string
	DataPath      string
	RestartPolicy RestartPolicy
	ReadyTimeout  time.Duration // default 60s
}

ConnectorConfig configures how the connector manages the outboard process.

type RestartPolicy

type RestartPolicy struct {
	MaxRestarts int           // 0 = unlimited
	BackoffBase time.Duration // Base delay for exponential backoff
	BackoffMax  time.Duration // Maximum backoff delay
	ResetWindow time.Duration // Time after which restart count resets
}

RestartPolicy configures automatic restart behavior.

func DefaultRestartPolicy

func DefaultRestartPolicy() RestartPolicy

DefaultRestartPolicy returns a restart policy with unlimited restarts.

type Server

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

Server is the outboard process side of the outboard framework. It reads the config written by the connector, sets up token-authenticated RPC, exposes the OutboardControl interface, and signals readiness.

func NewServer

func NewServer(ctx context.Context, configPath string, opts ...ServerOption) (*Server, error)

NewServer creates a new outboard Server by reading the config file at configPath. It creates a JSON slog handler writing to stdout (which the connector reads via FIFO), starts an RPC server with token authentication, and exposes the OutboardControl interface.

func (*Server) CheckVersion

CheckVersion implements OutboardControl.CheckVersion

func (*Server) Close

func (s *Server) Close() error

Close shuts down the outboard server.

func (*Server) Health

Health implements OutboardControl.Health

func (*Server) Logger

func (s *Server) Logger() *slog.Logger

Logger returns the server's logger (JSON handler writing to stdout FIFO).

func (*Server) RPCState

func (s *Server) RPCState() *rpc.State

RPCState returns the RPC state for registering additional domain-specific interfaces.

func (*Server) UpdateConfig

func (s *Server) UpdateConfig(fn func(*Config)) error

UpdateConfig re-reads the config and updates the ready state. This is used internally after the process has finished initializing.

type ServerOption

type ServerOption func(*Server)

ServerOption configures the outboard Server.

func WithShutdownFunc

func WithShutdownFunc(fn func()) ServerOption

WithShutdownFunc sets a function to call when a version mismatch triggers shutdown.

func WithVersion

func WithVersion(v uint64) ServerOption

WithVersion sets the version number reported by this outboard process.

type TokenAuthenticator

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

TokenAuthenticator implements rpc.Authenticator using a shared bearer token. It validates the Authorization header using constant-time comparison.

func NewTokenAuthenticator

func NewTokenAuthenticator(token string) *TokenAuthenticator

NewTokenAuthenticator creates a new TokenAuthenticator with the given token.

func (*TokenAuthenticator) Authenticate

func (t *TokenAuthenticator) Authenticate(ctx context.Context, r *http.Request) (*rpc.Identity, error)

Jump to

Keyboard shortcuts

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