lifecycle

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Nov 12, 2026 License: Apache-2.0 Imports: 25 Imported by: 0

Documentation

Index

Constants

View Source
const (
	LaunchKindWidth    = 10
	LaunchNameWidth    = 18
	LaunchStatusWidth  = 24
	LaunchCommandWidth = 40
)
View Source
const AgentLabel = "com.tscatalog.autostart"

AgentLabel is the launchd label for the one-shot login hook.

Variables

This section is empty.

Functions

func AutostartLogPath

func AutostartLogPath() (string, error)

AutostartLogPath is stdout/stderr for the login hook, not for service processes.

func CatalogOwns

func CatalogOwns(s catalog.Service) bool

CatalogOwns reports whether this catalog can stop the service. A process counts while its pidfile is still the process we started. An external helper counts when it has a stop argv. A compose project always counts. Anything else listening on the port is not ours.

func DialCompose

func DialCompose(ctx context.Context, svcs []catalog.Service) (*composeclient.Client, error)

DialCompose opens one client when a selected service is compose. It returns (nil, nil) when none are. A dial failure is returned to the caller.

func FollowFile

func FollowFile(ctx context.Context, path string, w io.Writer) error

FollowFile seeks to the end of path and copies new bytes to w every 200ms. It returns nil when ctx is done. A missing file is an error before the loop.

func FollowStreams

func FollowStreams(ctx context.Context, s catalog.Service, which string, out chan<- string) error

FollowStreams runs external argv and compose log streams until ctx is done. Process files are not included; the caller polls those.

func FormatLaunchTable

func FormatLaunchTable(rows []LaunchStatus) string

FormatLaunchTable renders process, container, and external rows for describe views.

func FormatPS

func FormatPS(rows []LaunchStatus) string

FormatPS renders the ps table. Empty id and shape print as "-". PID 0 prints as "-".

func InstallLoginAgent

func InstallLoginAgent(LoginAgent) error

InstallLoginAgent is only implemented on macOS.

func LocalHealthy

func LocalHealthy(s catalog.Service, rep Report) bool

LocalHealthy reports whether the process is accepting the catalog's local check. Public HTTPS and host approval are ignored.

func LocalReady

func LocalReady(ctx context.Context, s catalog.Service) bool

func Logs

func Logs(ctx context.Context, s catalog.Service, which string, tail int, follow, tailSet bool, w io.Writer, comp *composeclient.Client) error

Logs writes the selected rows to w. which is the ps NAME. Empty which follows every row of the service. tailSet is true when the user passed --tail; external argv ignores it.

func NeedsCompose

func NeedsCompose(svcs []catalog.Service) bool

NeedsCompose reports whether any spec resolves to compose.

func ReadSince

func ReadSince(path string, offset int64) ([]byte, int64, error)

ReadSince reads bytes appended to path after offset.

func ReadTail

func ReadTail(path string, n int) ([]string, error)

ReadTail returns the last n lines of path. n < 0 returns every line. n == 0 returns an empty slice. A missing file is "no log file".

func Reap

func Reap(args []string) error

Reap is the parent of a detached process. tscatalog exits after up, so this copy of the binary (re-exec'd with __reap) is what waits and records the exit.

func Restart

func Restart(ctx context.Context, cat *catalog.File, name string, w io.Writer) error

Restart starts name when nothing is listening. When the port is open, it stops that service first, and only if this catalog owns the process. requires are started locally and are not published. Stop never follows requires.

func Start

func Start(ctx context.Context, s catalog.Service, w io.Writer) error

Start runs each launch spec, then waits until the catalog local bind is ready.

func Stop

func Stop(ctx context.Context, s catalog.Service, w io.Writer) error

Stop runs each spec's stop argv, or SIGTERM to a detached pidfile.

func UninstallLoginAgent

func UninstallLoginAgent() error

UninstallLoginAgent is only implemented on macOS.

func ValueOK

func ValueOK(value string, expect []int) bool

ValueOK reports whether a probe cell is success. "tcp" is success. With an empty expect list, HTTP 2xx and 3xx are success.

func WithCompose

func WithCompose(ctx context.Context, c *composeclient.Client) context.Context

WithCompose attaches a client opened once for an up, stop, or restart.

Types

type Action

type Action int

Action is what a restart should do to the local process.

const (
	ActionNone Action = iota
	ActionStart
	ActionRestart
)

type Decision

type Decision struct {
	Action Action
	// Note explains ActionNone. Empty when a restart will run.
	Note string
}

Decision is whether restarting the process can fix a row.

func Decide

func Decide(s catalog.Service, rep Report, owned bool) Decision

Decide says whether restarting the process can fix this row. A healthy local process is not restarted, including when the host is only not-approved or draining.

type ExitRecord

type ExitRecord struct {
	State  string    `json:"state"`
	Code   int       `json:"code,omitempty"`
	Signal string    `json:"signal,omitempty"`
	At     time.Time `json:"at"`
}

ExitRecord is what the reaper writes when a process slot ends. State is exited, signaled, or stopped.

type LaunchState

type LaunchState string

LaunchState is the state column of one ps row.

const (
	LaunchRunning   LaunchState = "running"
	LaunchExited    LaunchState = "exited"
	LaunchSignaled  LaunchState = "signaled"
	LaunchStopped   LaunchState = "stopped"
	LaunchGone      LaunchState = "gone"
	LaunchUnwatched LaunchState = "unwatched"
)

type LaunchStatus

type LaunchStatus struct {
	Service string
	ID      string
	Index   int
	Shape   Shape
	State   LaunchState
	PID     int
	Detail  string
	// Command is the running argv for a process or container row.
	Command string
}

LaunchStatus is one ps row.

func LaunchStatuses

func LaunchStatuses(ctx context.Context, s catalog.Service, comp *composeclient.Client, dialErr error) []LaunchStatus

LaunchStatuses reports one row per process, one row per container, or one row for an external helper. A compose dial failure is a single gone row; it does not fail the caller. comp and dialErr are ignored for a service that has no compose spec.

func (LaunchStatus) DescribeParts

func (st LaunchStatus) DescribeParts() (key, status, command string)

DescribeParts is the describe/cat9s field for one row. The key is process, container, or external. Command is set only while running.

func (LaunchStatus) TableParts

func (st LaunchStatus) TableParts() (kind, name, status, command string)

TableParts is one launch row for the describe table.

type LogFile

type LogFile struct {
	Path   string
	Offset int64
	Prefix string
}

LogFile is a process log the cat9s view can poll.

func CaptureLogs

func CaptureLogs(ctx context.Context, s catalog.Service, which string, comp *composeclient.Client) (lines []string, files []LogFile, stream bool, err error)

CaptureLogs is the non-following read used by cat9s. stream is true when a later follow should start an external argv or compose Logs.

type LoginAgent

type LoginAgent struct {
	Executable string
	Catalog    string
	Path       string
	Log        string
}

LoginAgent is the macOS login hook. It is not the parent of catalog processes.

func (LoginAgent) Plist

func (a LoginAgent) Plist() ([]byte, error)

Plist is a RunAtLoad agent with no KeepAlive. stop of a child stays down until the next autostart, up, restart, or a new login session.

type Report

type Report struct {
	Name   string
	Bind   string
	Local  string
	Public string
	Host   string
	URL    string
	OK     bool
}

Report is one service's local bind, local HTTP, and public HTTPS.

func Probe

func Probe(ctx context.Context, s catalog.Service, publicBase, hostSummary string) Report

type Shape

type Shape string

Shape is the ps shape column. An external helper has an empty shape.

const (
	ShapeProcess   Shape = "process"
	ShapeContainer Shape = "container"
)

Jump to

Keyboard shortcuts

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