process

package
v0.0.0-...-82e5c22 Latest Latest
Warning

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

Go to latest
Published: Mar 2, 2023 License: MIT Imports: 13 Imported by: 0

Documentation

Overview

Package process provides a client and server for a remote process runner which streams stdin (client->server) and stdout & stderr (server->client). It uses WebSockets for bidi messaging so only requires an HTTPS server.

Processes are scoped to the WebSocket connection--that is, if the connection dies for any reason, the process is killed. If you want to run a process that survives across connections, then run it as a background process with disk/pipe buffering of stdin/stdout/stderr.

There are two messages in this protocol: "request" messages are sent client->server, and "response" messages are sent server->client. The schema for these messages is described in types.go.

The protocol proceeds as follows:

1. The client opens a WebSocket connection with the server 2. The client sends a request message containing the Command and Args fields, and optionally the Env and WD fields. 3. The client and server then exchange messages containing stdin, stdout, and stderr bytes while the process runs. 4. When the process exits, the server sends a response message with Exited=true and the ExitCode. 5. The client initiates closing of the WebSocket connection.

The server does not buffer any stdout or stderr, which generally means that the client must read them to completion before the process will exit cleanly.

Signaling is not implemented, but should be easy to add if the use case arises.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client struct {
	HTTPClient *http.Client
	URL        string
	Logger     *zap.SugaredLogger
}

func (*Client) StartProc

func (c *Client) StartProc(ctx context.Context, req StartProcRequest) (*Process, error)

type InputFD

type InputFD struct {
	// Reader is an input reader that returns bytes that should be sent to the input stream.
	// Note for stdin that the process will not exit until this reader returns an error or io.EOF.
	// If you signal the process and expect it to exit, then you should also return io.EOF from thi
	Reader io.Reader
	File   string
}

type OutputFD

type OutputFD struct {
	Writer io.Writer
	File   string
}

type Process

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

func (*Process) Signal

func (p *Process) Signal(ctx context.Context, sig syscall.Signal) error

func (*Process) Wait

type Server

type Server struct {
	Log *zap.SugaredLogger
}

func (*Server) ServeHTTP

func (s *Server) ServeHTTP(w http.ResponseWriter, r *http.Request)

type StartProcRequest

type StartProcRequest struct {
	Command string
	Args    []string
	Env     []string
	WD      string

	Stdin  InputFD
	Stdout OutputFD
	Stderr OutputFD
}

Jump to

Keyboard shortcuts

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