Documentation
¶
Overview ¶
Package daemon connects native Spacewave clients to the shared daemon.
Index ¶
- Constants
- Variables
- func NewStartupPipeLogger() *logrus.Entry
- func PrepareExecutable(statePath, source string) (published string, retErr error)
- func PrepareVerifiedExecutable(statePath, source, expectedSHA256 string) (string, error)
- func PublishReady(socketPath string) error
- func ServeArgs(statePath, pipeID string, launcher Launcher) []string
- func StartCopiedProcess(ctx context.Context, statePath, source string) error
- func StartExecutable(ctx context.Context, statePath string, executable string, launcher Launcher) error
- func StartProcess(ctx context.Context, statePath string) error
- func StartupTimeout() (time.Duration, error)
- func WaitStartup(ctx context.Context, listener net.Listener) error
- type Client
- type Connector
- type Launcher
- type StartupNotifier
Constants ¶
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 )
const SocketName = "spacewave.sock"
SocketName is the Resource socket beneath a Spacewave state root.
Variables ¶
var ErrStarting = errors.New("another daemon is starting")
ErrStarting means another process holds the state lease; callers watch its socket.
Functions ¶
func NewStartupPipeLogger ¶
NewStartupPipeLogger suppresses transport diagnostics on the private pipe.
func PrepareExecutable ¶
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 ¶
PrepareVerifiedExecutable publishes the selected executable only when its bytes match the digest accepted by the launcher controller.
func PublishReady ¶
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 StartCopiedProcess ¶
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 string, executable string, launcher Launcher, ) 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. launcher tells the daemon what started it.
func StartProcess ¶
StartProcess starts the current executable on demand for a command, with StartExecutable's readiness and child-custody guarantees.
func StartupTimeout ¶
StartupTimeout returns the configured startup deadline duration.
func WaitStartup ¶
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 ¶
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 ¶
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) 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 ¶
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 ¶
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 Launcher ¶
type Launcher string
Launcher records what started a detached daemon. The daemon reads it to decide whether to yield its state path to a manually started serve.
const ( // LauncherManual marks a daemon started by hand. LauncherManual Launcher = "" // LauncherCommand marks a daemon started on demand for a command. It // yields to a manually started serve. LauncherCommand Launcher = "command" // LauncherDesktop marks a daemon started by the desktop app. LauncherDesktop Launcher = "desktop" )
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.