daemon

package
v2.18.0-beta.2 Latest Latest
Warning

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

Go to latest
Published: Sep 22, 2026 License: GPL-3.0 Imports: 28 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsStalePIDConflict added in v2.18.0

func IsStalePIDConflict(err error) bool

IsStalePIDConflict reports whether err is the PID-file conflict that Start clears under the start gate. Callers that auto-start the service must treat it as "not running" and let Start recover it, otherwise a reused PID leaves the service unstartable from the wrapper.

func SpawnDaemon

func SpawnDaemon(cfg *config.Instance) (cleanup func(), err error)

SpawnDaemon spawns a daemon subprocess for service isolation (e.g., TUI mode). It waits for the service API to become available and returns a cleanup function. The cleanup function sends SIGTERM and waits for graceful shutdown with timeout. Returns a no-op cleanup function if service was already running.

Types

type Service

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

func NewService

func NewService(args ServiceArgs) (*Service, error)

func (*Service) Pid

func (s *Service) Pid() (int, error)

Pid returns the process ID of the current running service daemon.

func (*Service) Restart

func (s *Service) Restart() error

Restart is intentionally idempotent: if Running reports no live PID, Stop and waitForPIDExit are skipped and Start is called directly. When a PID is still active, Restart follows the full Stop -> waitForPIDExit -> Start sequence so pidRunning has confirmed the old process is gone before the replacement starts.

func (*Service) Running

func (s *Service) Running() (bool, error)

Running returns true if the service is running.

func (*Service) RunningForAutoStart added in v2.18.0

func (s *Service) RunningForAutoStart() (bool, error)

RunningForAutoStart reports whether the service is already running, for a caller that will start it if not.

It differs from Running in one way: a stale PID file left by a reused PID is reported as not running rather than as an error, because Start clears that under the start gate. Every platform wrapper checks this before auto-starting, and returning the error there left the service unstartable from the only entry point most users have. Any other error still stands.

func (*Service) ServiceHandler

func (s *Service) ServiceHandler(cmd *string) error

func (*Service) Start

func (s *Service) Start() error

Start a new service daemon in the background. If the service is already running (started by a peer wrapper invocation), Start returns nil without re-doing prep work.

func (*Service) Stop

func (s *Service) Stop() error

Stop the service daemon.

func (*Service) WaitForAPI

func (s *Service) WaitForAPI(cfg *config.Instance, maxWait, checkInterval time.Duration) error

WaitForAPI waits for the service API to become available with health monitoring. Returns nil if API became available, error if timeout or process crashed.

type ServiceArgs

type ServiceArgs struct {
	Platform platforms.Platform
	Config   *config.Instance
	Entry    ServiceEntry
	NoDaemon bool
}

type ServiceEntry

type ServiceEntry func() (*service.StartResult, error)

Jump to

Keyboard shortcuts

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