manager

package
v0.0.11 Latest Latest
Warning

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

Go to latest
Published: Jul 14, 2026 License: Apache-2.0 Imports: 24 Imported by: 0

Documentation

Overview

Package manager orchestrates daemon lifecycle operations: start, stop, restart, and status queries.

Index

Constants

View Source
const (
	CodeServiceAlreadyRegistered = "service_already_registered"
	CodeServiceNotRunning        = "service_not_running"
	CodeServiceNotRegistered     = "service_not_registered"
	CodeProcessNotFound          = "process_not_found"
	CodeAlreadyRunning           = "already_running"
)

Variables

View Source
var (
	ErrServiceAlreadyRegistered = errors.New("service already registered")
	ErrServiceNotRunning        = errors.New("service not running")
	ErrServiceNotRegistered     = errors.New("service not registered")
	ErrProcessNotFound          = errors.New("not found")
	ErrAlreadyRunning           = errors.New("already running")
)

Functions

func CreateErrorOutputLogFilename

func CreateErrorOutputLogFilename(serviceName string) string

func CreateLogDirPath

func CreateLogDirPath(baseDir string) string

func CreateOutputLogFilename

func CreateOutputLogFilename(serviceName string) string

func ErrorCode

func ErrorCode(err error) string

ErrorCode returns a machine-readable code for known sentinel errors, empty string otherwise.

func ErrorFromCode

func ErrorFromCode(code string) error

ErrorFromCode returns the sentinel error for a known code, nil otherwise.

func LoadServiceConfig

func LoadServiceConfig(configFilePath string) (*types.ServiceConfig, error)

func NewDaemonLogger

func NewDaemonLogger(logToFileAndConsole bool, verbose bool, logDir string, fileName string, maxFiles int, fileSizeLimit int64) (*slog.Logger, error)

NewDaemonLogger creates a *slog.Logger backed by a rotating JSON file. When logToFileAndConsole is true, output goes to both file and stdout. JSON format is Loki/Promtail-compatible.

func NewServiceCatalogEntry

func NewServiceCatalogEntry(name string, path string, configFile string) (*types.ServiceCatalogEntry, error)

func OpenLogFile

func OpenLogFile(logPath string) (*os.File, error)

func ValidateLogSink

func ValidateLogSink(sink *types.LogSink) []error

func ValidateRuntimeBinary

func ValidateRuntimeBinary(runtime types.Runtime) error

func ValidateRuntimePath

func ValidateRuntimePath(runtime types.Runtime) error

func ValidateServiceConfig

func ValidateServiceConfig(configFilePath string) (*types.ServiceConfig, []error)

Types

type CapturedWriter

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

CapturedWriter is a concurrency-safe io.Writer that retains up to maxCapturedStderr bytes, silently dropping anything past that (satisfies the io.Writer contract: never reports short writes without an error).

func (*CapturedWriter) String

func (c *CapturedWriter) String() string

func (*CapturedWriter) Write

func (c *CapturedWriter) Write(p []byte) (int, error)

type DaemonManager

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

func NewDaemonManager

func NewDaemonManager(ctx context.Context, socketPath string, pidFile string, socketTimeout time.Duration, verbose bool) (*DaemonManager, error)

func (*DaemonManager) AddServiceCatalogEntry

func (dm *DaemonManager) AddServiceCatalogEntry(service *types.ServiceCatalogEntry) error

func (*DaemonManager) ForceStopService

func (dm *DaemonManager) ForceStopService(name string) (StopServiceResult, error)

func (*DaemonManager) GetAllServiceCatalogEntries

func (dm *DaemonManager) GetAllServiceCatalogEntries() ([]types.ServiceCatalogEntry, error)

func (*DaemonManager) GetAllServiceInstances

func (dm *DaemonManager) GetAllServiceInstances() ([]types.ServiceInstance, error)

func (*DaemonManager) GetMostRecentProcessHistoryEntry

func (dm *DaemonManager) GetMostRecentProcessHistoryEntry(name string) (*types.ProcessHistory, error)

func (*DaemonManager) GetServiceCatalogEntry

func (dm *DaemonManager) GetServiceCatalogEntry(name string) (types.ServiceCatalogEntry, error)

func (*DaemonManager) GetServiceInstance

func (dm *DaemonManager) GetServiceInstance(name string) (*types.ServiceInstance, error)

func (*DaemonManager) GetServiceLogFilePath

func (dm *DaemonManager) GetServiceLogFilePath(serviceName string, errorLog bool) (*string, error)

func (*DaemonManager) IsServiceRegistered

func (dm *DaemonManager) IsServiceRegistered(name string) (bool, error)

func (*DaemonManager) NewServiceLogFiles

func (dm *DaemonManager) NewServiceLogFiles(serviceName string) (logPath string, errorLogPath string, err error)

func (*DaemonManager) RemoveServiceCatalogEntry

func (dm *DaemonManager) RemoveServiceCatalogEntry(name string) (bool, error)

func (*DaemonManager) RemoveServiceInstance

func (dm *DaemonManager) RemoveServiceInstance(name string) (bool, error)

func (*DaemonManager) RestartService

func (dm *DaemonManager) RestartService(name string, gracePeriod time.Duration, tickerPeriod time.Duration) (int, error)

func (*DaemonManager) StartService

func (dm *DaemonManager) StartService(name string) (int, error)

func (*DaemonManager) StopService

func (dm *DaemonManager) StopService(name string, gracePeriod time.Duration, tickerPeriod time.Duration) (StopServiceResult, error)

func (*DaemonManager) UpdateServiceCatalogEntry

func (dm *DaemonManager) UpdateServiceCatalogEntry(name string, newDirectoryPath string, newConfigFileName string) error

type Executor

type Executor interface {
	LookPath(file string) (string, error)
	CommandContext(ctx context.Context, name string, arg ...string) *exec.Cmd
}

Executor abstracts os/exec so tests can inject a fake without requiring runtime binaries (node, bun, deno) in the system PATH.

type LocalManager

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

func NewLocalManager

func NewLocalManager(db *database.DB, baseDir string, ctx context.Context, logger *slog.Logger, opts ...LocalManagerOption) *LocalManager

func (*LocalManager) AddServiceCatalogEntry

func (m *LocalManager) AddServiceCatalogEntry(newServiceCatalogEntry *types.ServiceCatalogEntry) error

func (*LocalManager) ForceStopService

func (m *LocalManager) ForceStopService(name string) (StopServiceResult, error)

func (*LocalManager) GetAllServiceCatalogEntries

func (m *LocalManager) GetAllServiceCatalogEntries() ([]types.ServiceCatalogEntry, error)

func (*LocalManager) GetAllServiceInstances

func (m *LocalManager) GetAllServiceInstances() ([]types.ServiceInstance, error)

func (*LocalManager) GetMostRecentProcessHistoryEntry

func (m *LocalManager) GetMostRecentProcessHistoryEntry(name string) (*types.ProcessHistory, error)

func (*LocalManager) GetServiceCatalogEntry

func (m *LocalManager) GetServiceCatalogEntry(name string) (types.ServiceCatalogEntry, error)

func (*LocalManager) GetServiceInstance

func (m *LocalManager) GetServiceInstance(name string) (*types.ServiceInstance, error)

func (*LocalManager) GetServiceLogFilePath

func (m *LocalManager) GetServiceLogFilePath(serviceName string, errorLog bool) (*string, error)

func (*LocalManager) IsServiceRegistered

func (m *LocalManager) IsServiceRegistered(name string) (bool, error)

func (*LocalManager) LogToServiceStderr

func (m *LocalManager) LogToServiceStderr(serviceName string, message string) error

func (*LocalManager) LogToServiceStdout

func (m *LocalManager) LogToServiceStdout(serviceName string, message string) error

func (*LocalManager) NewServiceLogFiles

func (m *LocalManager) NewServiceLogFiles(serviceName string) (logPath string, errorLogPath string, err error)

func (*LocalManager) RemoveServiceCatalogEntry

func (m *LocalManager) RemoveServiceCatalogEntry(name string) (bool, error)

func (*LocalManager) RemoveServiceInstance

func (m *LocalManager) RemoveServiceInstance(name string) (bool, error)

func (*LocalManager) RestartService

func (m *LocalManager) RestartService(name string, gracePeriod time.Duration, tickerPeriod time.Duration) (pgid int, err error)

func (*LocalManager) StartService

func (m *LocalManager) StartService(name string) (pgid int, err error)

func (*LocalManager) StopService

func (m *LocalManager) StopService(name string, gracePeriod time.Duration, tickerPeriod time.Duration) (StopServiceResult, error)

func (*LocalManager) UpdateServiceCatalogEntry

func (m *LocalManager) UpdateServiceCatalogEntry(name string, newDirectoryPath string, newConfigFileName string) error

func (*LocalManager) WaitPipes

func (m *LocalManager) WaitPipes()

WaitPipes blocks until all pipe-forwarding goroutines have exited. Call this in test cleanup after stopping services to avoid goroutine leaks.

type LocalManagerOption

type LocalManagerOption func(*LocalManager)

func WithExecutor

func WithExecutor(e Executor) LocalManagerOption

type RotatingFileWriter

type RotatingFileWriter struct {
	LogPath string
	// contains filtered or unexported fields
}

RotatingFileWriter is an io.Writer that rotates the underlying log file once it exceeds maxSize bytes. It is used as the sink for the daemon's slog.Logger.

func (*RotatingFileWriter) Write

func (w *RotatingFileWriter) Write(p []byte) (n int, err error)

type ServiceLogFilesResult

type ServiceLogFilesResult struct {
	LogFilePath      string `json:"logFile"`
	ErrorLogFilePath string `json:"errorLogFile"`
}

type ServiceManager

type ServiceManager interface {
	GetServiceInstance(name string) (*types.ServiceInstance, error)
	GetAllServiceInstances() ([]types.ServiceInstance, error)
	RemoveServiceInstance(name string) (bool, error)

	ForceStopService(name string) (StopServiceResult, error)
	RestartService(name string, gracePeriod time.Duration, tickerPeriod time.Duration) (int, error)
	StartService(name string) (int, error)
	StopService(name string, gracePeriod time.Duration, tickerPeriod time.Duration) (StopServiceResult, error)

	AddServiceCatalogEntry(service *types.ServiceCatalogEntry) error
	GetAllServiceCatalogEntries() ([]types.ServiceCatalogEntry, error)
	GetServiceCatalogEntry(name string) (types.ServiceCatalogEntry, error)
	IsServiceRegistered(name string) (bool, error)
	RemoveServiceCatalogEntry(name string) (bool, error)
	UpdateServiceCatalogEntry(name string, newDirectoryPath string, newConfigFileName string) error

	GetMostRecentProcessHistoryEntry(name string) (*types.ProcessHistory, error)

	NewServiceLogFiles(serviceName string) (logPath string, errorLogPath string, err error)
	GetServiceLogFilePath(serviceName string, errorLog bool) (*string, error)
}

type StopRequestResult

type StopRequestResult struct {
	AlreadyDead map[int]bool
	Errored     map[int]string
	Pending     map[int]bool
}

type StopServiceResult

type StopServiceResult struct {
	Errored   map[int]string
	Stopped   map[int]bool
	StaleData map[int]string
}

Jump to

Keyboard shortcuts

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