Documentation
¶
Index ¶
- Variables
- func IsStalePIDConflict(err error) bool
- func SpawnDaemon(cfg *config.Instance) (cleanup func(), err error)
- type Service
- func (s *Service) Pid() (int, error)
- func (s *Service) Restart() error
- func (s *Service) Running() (bool, error)
- func (s *Service) RunningForAutoStart() (bool, error)
- func (s *Service) ServiceHandler(cmd *string) error
- func (s *Service) Start() error
- func (s *Service) Stop() error
- func (s *Service) WaitForAPI(cfg *config.Instance, maxWait, checkInterval time.Duration) error
- type ServiceArgs
- type ServiceEntry
Constants ¶
This section is empty.
Variables ¶
var ErrUnreadablePIDFile = errors.New("pid file does not contain a pid")
ErrUnreadablePIDFile reports a pid file whose contents are not a number: truncated to nothing by an interrupted write, or left as debris. It is handled like a stale file rather than as a fatal error - refusing to start because of it leaves the service permanently down with no way for a user to know why, and on platforms whose temp directory survives a reboot, not even restarting clears it.
Functions ¶
func IsStalePIDConflict ¶ added in v2.18.0
IsStalePIDConflict reports whether err is a PID-file fault that Start clears under the start gate: a reused PID, or a file that names no process at all. Callers that auto-start the service must treat it as "not running" and let Start recover it, otherwise the service is unstartable from the wrapper.
func SpawnDaemon ¶
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) Restart ¶
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) RunningForAutoStart ¶ added in v2.18.0
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 or holding no PID at all, is reported as not running rather than as an error, because Start clears it 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 ¶
type ServiceArgs ¶
type ServiceEntry ¶
type ServiceEntry func() (*service.StartResult, error)