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

daemon

package
v0.57.22 Latest Latest
Warning

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

Go to latest
Published: Oct 2, 2026 License: Apache-2.0 Imports: 26 Imported by: 0

Documentation

Overview

Package daemon connects native Spacewave clients to the shared daemon.

Index

Constants

View Source
const (
	// StartupTimeoutEnvVar selects the startup and Resource Init deadline.
	StartupTimeoutEnvVar = "SPACEWAVE_DAEMON_STARTUP_TIMEOUT"
	// TracePathEnvVar forwards the optional daemon runtime trace path.
	TracePathEnvVar = "SPACEWAVE_DAEMON_TRACE"
	// DefaultStartupTimeout bounds startup without expiring retained clients.
	DefaultStartupTimeout = time.Minute
)
View Source
const SocketName = "spacewave.sock"

SocketName is the Resource socket beneath a Spacewave state root.

Variables

View Source
var ErrStarting = errors.New("another daemon is starting")

ErrStarting means another process holds the state lease; callers watch its socket.

Functions

func NewStartupPipeLogger

func NewStartupPipeLogger() *logrus.Entry

NewStartupPipeLogger suppresses transport diagnostics on the private pipe.

func PrepareExecutable

func PrepareExecutable(statePath, source string) (published string, retErr error)

PrepareExecutable publishes a digest-named executable without replacing an existing path, including one that a daemon may currently be executing. The caller selects and verifies the source before preparing it for startup.

func PrepareVerifiedExecutable

func PrepareVerifiedExecutable(statePath, source, expectedSHA256 string) (string, error)

PrepareVerifiedExecutable publishes the selected executable only when its bytes match the digest accepted by the launcher controller.

func PublishReady

func PublishReady(socketPath string) error

PublishReady wakes connectors after the daemon's listener and Resource service are ready and startup custody has transferred. Only the daemon holding the state lease may call it. Both native and distribution serve use this event, since listen itself produces no socket pathname event.

The file is a notification, not evidence of a live daemon: connectors subscribe before dialing and always complete Resource Init. Rewriting it emits a fresh event on each startup, including when a previous daemon left the file behind.

func ServeArgs

func ServeArgs(statePath, pipeID string) []string

ServeArgs returns the current executable's detached daemon invocation.

func StartCopiedProcess

func StartCopiedProcess(ctx context.Context, statePath, source string) error

StartCopiedProcess starts a verified, state-local copy of the desktop executable. The digest path remains available while that daemon is running.

func StartExecutable

func StartExecutable(ctx context.Context, statePath, executable string) error

StartExecutable starts the selected executable and transfers custody before returning success. Failure stops and joins only this attempt's unready child. If the OS refuses termination without a verified exit, failure releases the handles and reports that the unacknowledged child may remain alive. It never requests shutdown through the shared socket.

func StartProcess

func StartProcess(ctx context.Context, statePath string) error

StartProcess starts the current executable with StartExecutable's readiness and child-custody guarantees.

func StartupTimeout

func StartupTimeout() (time.Duration, error)

StartupTimeout returns the configured startup deadline duration.

func WaitStartup

func WaitStartup(ctx context.Context, listener net.Listener) error

WaitStartup acknowledges a ready child's transfer to independent lifetime. A failed return guarantees that no acknowledgement was written. The child must not accept public clients until it receives that acknowledgement.

Types

type Client

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

Client retains one initialized Resource connection. Closing it never stops the daemon, including when this caller started that daemon.

func Connect

func Connect(ctx context.Context, statePath, socketPath string) (*Client, error)

Connect resolves a native daemon target and completes Resource Init. An explicit socket is connect-only; otherwise it starts the current executable in detached serve mode when the state root has no daemon. The caller owns only the returned client, never the ready daemon.

func NewClient

func NewClient(ctx context.Context, conn net.Conn) (*Client, error)

NewClient initializes Resource service on conn and takes ownership of conn on both success and failure. The caller must Close a successful client.

func (*Client) Close

func (c *Client) Close()

Close releases the root, Resource stream and socket. It never signals a process.

func (*Client) Conn

func (c *Client) Conn() net.Conn

Conn returns the transport for connection-scoped control operations.

func (*Client) RPC

func (c *Client) RPC() srpc.Client

RPC returns the socket's service client.

func (*Client) Resources

func (c *Client) Resources() *resource_client.Client

Resources returns the initialized Resource client.

func (*Client) Root

func (c *Client) Root() *s4wave_root.Root

Root returns the root reference retained by this client.

type Connector

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

Connector resolves native daemon targets and converges concurrent launches through socket and readiness events. Only the daemon holding the state lease may bind and publish readiness.

func NewConnector

func NewConnector(dial func(context.Context, string) (net.Conn, error), start func(context.Context, string) error) *Connector

NewConnector constructs a connector. Nil callbacks select the native dialer and detached executable launcher; callbacks allow isolated process fixtures.

func (*Connector) Connect

func (c *Connector) Connect(ctx context.Context, statePath, socketPath string) (*Client, error)

Connect completes Resource Init on the resolved daemon. Closing the returned client releases only its connection, including when this call started it.

func (*Connector) Dial

func (c *Connector) Dial(ctx context.Context, statePath, socketPath string) (net.Conn, error)

Dial connects to the resolved target. An explicit socket is connect-only and does not resolve or create a state root. Otherwise the root follows storagepath defaults and only absence or refusal permits starting a detached daemon. The returned connection still needs Resource Init to establish readiness.

type StartupNotifier

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

StartupNotifier transfers a child from launcher custody to daemon lifetime. Its methods run serially on the serving goroutine.

func NewStartupNotifier

func NewStartupNotifier(ctx context.Context, statePath, pipeID string) (*StartupNotifier, error)

NewStartupNotifier connects to the launcher's private pipe. An empty pipe ID selects manual serve, which needs no launcher acknowledgement.

func (*StartupNotifier) Close

func (n *StartupNotifier) Close()

Close releases the private pipe without changing the daemon's lifetime.

func (*StartupNotifier) Error

func (n *StartupNotifier) Error(err error)

Error reports a startup failure, preserving lease contention as a distinct event so a losing launcher can attach to the winner without takeover.

func (*StartupNotifier) Ready

func (n *StartupNotifier) Ready(ctx context.Context) error

Ready reports a successfully initialized Resource service and waits for the parent's custody acknowledgement. Call before accepting public connections.

Jump to

Keyboard shortcuts

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