catch

package
v0.0.0-...-3aa0a94 Latest Latest
Warning

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

Go to latest
Published: Jun 17, 2025 License: Apache-2.0 Imports: 66 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"
	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 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 {
	Signer               ssh.Signer
	DB                   *db.Store
	DefaultUser          string
	RootDir              string
	ServicesRoot         string
	MountsRoot           string
	InternalRegistryAddr string
	ExternalRegistryAddr string
	RegistryRoot         string
	LocalClient          *tailscale.LocalClient
}

Config consists of an `Address` (ip:port) and an `SSHConfig` that is used to configure the SSH server.

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

	// 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
	// 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:"-"`

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

	// SSHSessionCloser is an io.Closer that closes the SSH session.
	SSHSessionCloser 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 Server

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

Server is an SSH server that handles exec commands and SFTP subsystem requests. It listens on a specified address and uses the provided SSH server configuration. The server can be configured with a CmdHandlerFunc to handle exec commands and a PutHandlerFunc to handle SFTP PUT requests.

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) RemoveEventListener

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

func (*Server) RemoveService

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

RemoveService checks if service is stopped, removes the service directory from the filesystem, and removes the service from the database.

func (*Server) SSHHandler

func (s *Server) SSHHandler(session gssh.Session)

func (*Server) ServeInternalRegistry

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

func (*Server) ServeSSH

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

ServeSSH starts the server and listens for incoming connections. It blocks until an error occurs.

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.

func (*Server) WebMux

func (s *Server) WebMux() (http.Handler, error)

type ServerInfo

type ServerInfo struct {
	Version string `json:"version"`
	GOOS    string `json:"goos"`
	GOARCH  string `json:"goarch"`
}

func GetInfo

func GetInfo() ServerInfo

type ServiceDataType

type ServiceDataType string

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