catch

package
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: Jan 17, 2026 License: BSD-3-Clause Imports: 64 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// SystemService is the name of the system meta-service that manages the server.
	SystemService = "sys"
	// CatchService is the name of the self-service that manages the server.
	CatchService = "catch"
)
View Source
const (
	ServiceDataTypeService    ServiceDataType = "service"
	ServiceDataTypeCron       ServiceDataType = "cron"
	ServiceDataTypeDocker     ServiceDataType = "docker"
	ServiceDataTypeBinary     ServiceDataType = "binary"
	ServiceDataTypeTypeScript ServiceDataType = "typescript"
	ServiceDataTypePython     ServiceDataType = "python"
	ServiceDataTypeUnknown    ServiceDataType = "unknown"

	ComponentStatusStarting ComponentStatus = "starting"
	ComponentStatusRunning  ComponentStatus = "running"
	ComponentStatusStopping ComponentStatus = "stopping"
	ComponentStatusStopped  ComponentStatus = "stopped"
	ComponentStatusUnknown  ComponentStatus = "unknown"
)

Variables

View Source
var DockerStatusesUnknown = svc.DockerComposeStatus{}

Functions

func First

func First[T1, T2 any](t1 T1, _ T2) T1

func Version

func Version() string

Version returns the release version if set, otherwise falls back to the commit hash.

func VersionCommit

func VersionCommit() string

VersionCommit returns the commit hash of the current build.

Types

type ComponentStatus

type ComponentStatus string

func ComponentStatusFromServiceStatus

func ComponentStatusFromServiceStatus(st svc.Status) ComponentStatus

type ComponentStatusData

type ComponentStatusData struct {
	Name   string          `json:"name"`
	Status ComponentStatus `json:"status"`
}

type Config

type Config struct {
	DB                   *db.Store
	DefaultUser          string
	InstallUser          string
	InstallHost          string
	RootDir              string
	ServicesRoot         string
	MountsRoot           string
	InternalRegistryAddr string
	ExternalRegistryAddr string
	RegistryRoot         string
	ContainerdSocket     string
	RegistryStorage      registry.Storage
	LocalClient          *local.Client
	AuthorizeFunc        func(ctx context.Context, remoteAddr string) error `json:"-"`
}

Config contains the server dependencies and filesystem paths.

type Event

type Event struct {
	// Time is the time the event was created in milliseconds since the epoch.
	Time        int64     `json:"time"`
	ServiceName string    `json:"serviceName"`
	Type        EventType `json:"type"`
	Data        EventData `json:"data,omitempty"`
}

type EventData

type EventData struct {
	Data any
}

func (EventData) MarshalJSON

func (m EventData) MarshalJSON() ([]byte, error)

MarshalJSON returns m as the JSON encoding of m.

type EventListener

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

type EventType

type EventType string
const (
	EventTypeUnknown              EventType = "Unknown"
	EventTypeHeartbeat            EventType = "Heartbeat"
	EventTypeServiceStatusChanged EventType = "ServiceStatusChanged"
	EventTypeServiceDeleted       EventType = "ServiceDeleted"
	EventTypeServiceCreated       EventType = "ServiceCreated"
	EventTypeServiceConfigChanged EventType = "ServiceConfigChanged"
	EventTypeServiceConfigStaged  EventType = "ServiceConfigStaged"
)

type FileInstaller

type FileInstaller struct {
	File *os.File
	// contains filtered or unexported fields
}

func NewFileInstaller

func NewFileInstaller(s *Server, cfg FileInstallerCfg) (*FileInstaller, error)

func (*FileInstaller) Close

func (i *FileInstaller) Close() (err error)

Close closes the temporary file and installs the service.

func (*FileInstaller) Fail

func (i *FileInstaller) Fail()

func (*FileInstaller) Rate

func (i *FileInstaller) Rate() float64

func (*FileInstaller) Received

func (i *FileInstaller) Received() float64

func (*FileInstaller) Wait

func (i *FileInstaller) Wait() error

func (*FileInstaller) Write

func (i *FileInstaller) Write(p []byte) (n int, err error)

func (*FileInstaller) WriteAt

func (i *FileInstaller) WriteAt(p []byte, offset int64) (n int, err error)

type FileInstallerCfg

type FileInstallerCfg struct {
	InstallerCfg
	EnvFile bool

	Args      []string
	Network   NetworkOpts
	StageOnly bool
	NoBinary  bool
	Publish   []string
	// PayloadName preserves the original filename for type detection.
	PayloadName string

	// NewCmd, if set, will be used to create a new exec.Cmd.
	NewCmd func(name string, arg ...string) *exec.Cmd
}

type Installer

type Installer struct {
	NewCmd func(name string, arg ...string) *exec.Cmd
	// contains filtered or unexported fields
}

Installer is an io.WriteCloser that writes the received binary to a file and installs the service when closed.

func (*Installer) Install

func (si *Installer) Install() error

Install installs the service.

func (*Installer) InstallGen

func (si *Installer) InstallGen(gen int) error

type InstallerCfg

type InstallerCfg struct {
	ServiceName string
	User        string
	// Pull forces docker compose services to pull images on install.
	Pull bool
	// Printer is a function to print messages to the client.
	Printer func(string, ...any) `json:"-"`

	// ClientOut is the writer to send messages to stdout on the client.
	ClientOut io.Writer `json:"-"`

	// UI is used to render user-facing install progress.
	UI ProgressUI `json:"-"`

	// Timer, if set, specifies that the service should be installed as a timer service.
	Timer *svc.TimerConfig `json:"-"`

	// ClientCloser is an io.Closer that closes the client connection.
	ClientCloser io.Closer `json:"-"`
}

InstallerCfg is the configuration for installing a service.

type MacvlanOpts

type MacvlanOpts struct {
	Mac    string
	Parent string
	VLAN   int
}

type NetworkOpts

type NetworkOpts struct {
	Interfaces string
	Tailscale  TailscaleOpts
	Macvlan    MacvlanOpts
}

type ProgressUI

type ProgressUI interface {
	Start()
	Stop()
	Suspend()
	StartStep(name string)
	UpdateDetail(detail string)
	DoneStep(detail string)
	FailStep(detail string)
	Printer(format string, args ...any)
}

type PtySpec

type PtySpec struct {
	Term   string
	Window PtyWindow
}

type PtyWindow

type PtyWindow struct {
	Width  int
	Height int
}

type RemoveReport

type RemoveReport struct {
	Warnings []error
}

type Server

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

Server hosts the RPC handlers that manage services and exec commands.

func NewServer

func NewServer(config *Config) *Server

NewServer creates a new Server instance with the provided configuration.

func NewUnstartedServer

func NewUnstartedServer(config *Config) *Server

NewUnstartedServer creates a new Server instance with the provided configuration but does not start it.

func (*Server) AddEventListener

func (s *Server) AddEventListener(ch chan<- Event, filter func(Event) bool) set.Handle

func (*Server) DockerComposeStatus

func (s *Server) DockerComposeStatus(ns string) (svc.DockerComposeStatus, error)

DockerComposeStatus returns the statuses of the containers for the given service.

func (*Server) DockerComposeStatuses

func (s *Server) DockerComposeStatuses() (map[string]svc.DockerComposeStatus, error)

DockerComposeStatuses returns the status of all Docker services. The keys are the service names and the values are the statuses. Possible statuses are svc.StatusRunning, svc.StatusStopped, and svc.StatusUnknown.

func (*Server) IsServiceRunning

func (s *Server) IsServiceRunning(name string) (bool, error)

IsServiceRunning returns whether the service with the given name is running. If this is a Docker service, it will return true if any of the containers are running.

func (*Server) NewInstaller

func (s *Server) NewInstaller(cfg InstallerCfg) (*Installer, error)

NewInstaller returns a new SystemdInstaller for the given service name. The binary will be stored in the service's bin directory and installed as a service when closed.

func (*Server) PublishEvent

func (s *Server) PublishEvent(event Event)

func (*Server) RPCMux

func (s *Server) RPCMux() http.Handler

RPCMux returns the RPC handler that serves JSON-RPC and streaming endpoints.

func (*Server) RegistryHandler

func (s *Server) RegistryHandler() http.Handler

func (*Server) RemoveEventListener

func (s *Server) RemoveEventListener(h set.Handle)

func (*Server) RemoveService

func (s *Server) RemoveService(name string) (*RemoveReport, error)

RemoveService removes the service from the database and attempts to clean up related files/devices. It always removes the DB entry if possible, returning cleanup warnings separately from fatal errors.

func (*Server) ServeInternalRegistry

func (s *Server) ServeInternalRegistry(listener net.Listener) error

func (*Server) Shutdown

func (s *Server) Shutdown()

func (*Server) Start

func (s *Server) Start()

Start starts the server. It panics if the server is already started.

func (*Server) SystemdStatus

func (s *Server) SystemdStatus(ns string) (svc.Status, error)

SystemdStatus returns the status of the service with the given name. Possible statuses are svc.StatusRunning, svc.StatusStopped, and svc.StatusUnknown.

func (*Server) SystemdStatuses

func (s *Server) SystemdStatuses() (map[string]svc.Status, error)

SystemdStatuses returns the status of all systemd services. The keys are the service names and the values are the statuses. Possible statuses are svc.StatusRunning, svc.StatusStopped, and svc.StatusUnknown.

type ServerInfo

type ServerInfo struct {
	Version     string `json:"version"`
	GOOS        string `json:"goos"`
	GOARCH      string `json:"goarch"`
	InstallUser string `json:"installUser,omitempty"`
	InstallHost string `json:"installHost,omitempty"`
	RootDir     string `json:"rootDir,omitempty"`
	ServicesDir string `json:"servicesDir,omitempty"`
}

func GetInfo

func GetInfo() ServerInfo

func GetInfoWithConfig

func GetInfoWithConfig(cfg *Config) ServerInfo

func GetInfoWithInstallUser

func GetInfoWithInstallUser(installUser string, installHost string) ServerInfo

type ServiceDataType

type ServiceDataType string

func ServiceDataTypeForService

func ServiceDataTypeForService(sv db.ServiceView) ServiceDataType

func ServiceDataTypeFromServiceType

func ServiceDataTypeFromServiceType(st db.ServiceType) ServiceDataType

func ServiceDataTypeFromUnitType

func ServiceDataTypeFromUnitType(unitType string) ServiceDataType

type ServiceEnabler

type ServiceEnabler interface {
	Enable() error
	Disable() error
}

ServiceEnabler is an interface extension for services that can be enabled and disabled.

type ServiceRunner

type ServiceRunner interface {
	SetNewCmd(func(string, ...string) *exec.Cmd)

	Start() error
	Stop() error
	Restart() error

	Logs(opts *svc.LogOptions) error

	Remove() error
}

ServiceRunner is an interface for the minimal set of methods required to manage a service.

type ServiceStatusData

type ServiceStatusData struct {
	ServiceName     string                `json:"serviceName"`
	ServiceType     ServiceDataType       `json:"serviceType"`
	ComponentStatus []ComponentStatusData `json:"components"`
}

type TailscaleOpts

type TailscaleOpts struct {
	Version  string
	ExitNode string
	Tags     []string
	AuthKey  string
}

Jump to

Keyboard shortcuts

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