Documentation
¶
Overview ¶
Package manager orchestrates daemon lifecycle operations: start, stop, restart, and status queries.
Index ¶
- Constants
- Variables
- func CreateErrorOutputLogFilename(serviceName string) string
- func CreateLogDirPath(baseDir string) string
- func CreateOutputLogFilename(serviceName string) string
- func ErrorCode(err error) string
- func ErrorFromCode(code string) error
- func LoadServiceConfig(configFilePath string) (*types.ServiceConfig, error)
- func NewDaemonLogger(logToFileAndConsole bool, verbose bool, logDir string, fileName string, ...) (*slog.Logger, error)
- func NewServiceCatalogEntry(name string, path string, configFile string) (*types.ServiceCatalogEntry, error)
- func OpenLogFile(logPath string) (*os.File, error)
- func ValidateLogSink(sink *types.LogSink) []error
- func ValidateRuntimeBinary(runtime types.Runtime) error
- func ValidateRuntimePath(runtime types.Runtime) error
- func ValidateServiceConfig(configFilePath string) (*types.ServiceConfig, []error)
- type CapturedWriter
- type DaemonManager
- func (dm *DaemonManager) AddServiceCatalogEntry(service *types.ServiceCatalogEntry) error
- func (dm *DaemonManager) ForceStopService(name string) (StopServiceResult, error)
- func (dm *DaemonManager) GetAllServiceCatalogEntries() ([]types.ServiceCatalogEntry, error)
- func (dm *DaemonManager) GetAllServiceInstances() ([]types.ServiceInstance, error)
- func (dm *DaemonManager) GetMostRecentProcessHistoryEntry(name string) (*types.ProcessHistory, error)
- func (dm *DaemonManager) GetServiceCatalogEntry(name string) (types.ServiceCatalogEntry, error)
- func (dm *DaemonManager) GetServiceInstance(name string) (*types.ServiceInstance, error)
- func (dm *DaemonManager) GetServiceLogFilePath(serviceName string, errorLog bool) (*string, error)
- func (dm *DaemonManager) IsServiceRegistered(name string) (bool, error)
- func (dm *DaemonManager) NewServiceLogFiles(serviceName string) (logPath string, errorLogPath string, err error)
- func (dm *DaemonManager) RemoveServiceCatalogEntry(name string) (bool, error)
- func (dm *DaemonManager) RemoveServiceInstance(name string) (bool, error)
- func (dm *DaemonManager) RestartService(name string, gracePeriod time.Duration, tickerPeriod time.Duration) (int, error)
- func (dm *DaemonManager) StartService(name string) (int, error)
- func (dm *DaemonManager) StopService(name string, gracePeriod time.Duration, tickerPeriod time.Duration) (StopServiceResult, error)
- func (dm *DaemonManager) UpdateServiceCatalogEntry(name string, newDirectoryPath string, newConfigFileName string) error
- type Executor
- type LocalManager
- func (m *LocalManager) AddServiceCatalogEntry(newServiceCatalogEntry *types.ServiceCatalogEntry) error
- func (m *LocalManager) ForceStopService(name string) (StopServiceResult, error)
- func (m *LocalManager) GetAllServiceCatalogEntries() ([]types.ServiceCatalogEntry, error)
- func (m *LocalManager) GetAllServiceInstances() ([]types.ServiceInstance, error)
- func (m *LocalManager) GetMostRecentProcessHistoryEntry(name string) (*types.ProcessHistory, error)
- func (m *LocalManager) GetServiceCatalogEntry(name string) (types.ServiceCatalogEntry, error)
- func (m *LocalManager) GetServiceInstance(name string) (*types.ServiceInstance, error)
- func (m *LocalManager) GetServiceLogFilePath(serviceName string, errorLog bool) (*string, error)
- func (m *LocalManager) IsServiceRegistered(name string) (bool, error)
- func (m *LocalManager) LogToServiceStderr(serviceName string, message string) error
- func (m *LocalManager) LogToServiceStdout(serviceName string, message string) error
- func (m *LocalManager) NewServiceLogFiles(serviceName string) (logPath string, errorLogPath string, err error)
- func (m *LocalManager) RemoveServiceCatalogEntry(name string) (bool, error)
- func (m *LocalManager) RemoveServiceInstance(name string) (bool, error)
- func (m *LocalManager) RestartService(name string, gracePeriod time.Duration, tickerPeriod time.Duration) (pgid int, err error)
- func (m *LocalManager) StartService(name string) (pgid int, err error)
- func (m *LocalManager) StopService(name string, gracePeriod time.Duration, tickerPeriod time.Duration) (StopServiceResult, error)
- func (m *LocalManager) UpdateServiceCatalogEntry(name string, newDirectoryPath string, newConfigFileName string) error
- func (m *LocalManager) WaitPipes()
- type LocalManagerOption
- type RotatingFileWriter
- type ServiceLogFilesResult
- type ServiceManager
- type StopRequestResult
- type StopServiceResult
Constants ¶
const ( CodeServiceAlreadyRegistered = "service_already_registered" CodeServiceNotRunning = "service_not_running" CodeServiceNotRegistered = "service_not_registered" CodeProcessNotFound = "process_not_found" CodeAlreadyRunning = "already_running" )
Variables ¶
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 CreateLogDirPath ¶
func CreateOutputLogFilename ¶
func ErrorCode ¶
ErrorCode returns a machine-readable code for known sentinel errors, empty string otherwise.
func ErrorFromCode ¶
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 ValidateLogSink ¶
func ValidateRuntimeBinary ¶
func ValidateRuntimePath ¶
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
type DaemonManager ¶
type DaemonManager struct {
// contains filtered or unexported fields
}
func NewDaemonManager ¶
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 (*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 (*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.
type ServiceLogFilesResult ¶
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)
}