daemon

package
v1.4.3 Latest Latest
Warning

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

Go to latest
Published: Mar 12, 2026 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

Package daemon provides the core daemon runner for WarpDL. It manages the lifecycle of the download service including start, stop, and graceful shutdown capabilities.

Index

Constants

View Source
const (
	// DefaultServiceName is the default Windows service name.
	DefaultServiceName = "WarpDL"

	// DefaultDisplayName is the default Windows service display name.
	DefaultDisplayName = "WarpDL Download Manager"

	// DefaultDescription is the default Windows service description.
	DefaultDescription = "High-performance parallel download manager"
)

Service name constants for Windows service registration.

Variables

View Source
var (
	// ErrAlreadyRunning is returned when Start() is called on a running daemon.
	ErrAlreadyRunning = errors.New("daemon is already running")

	// ErrNotRunning is returned when Shutdown() is called on a stopped daemon.
	ErrNotRunning = errors.New("daemon is not running")

	// ErrShutdownTimeout is returned when shutdown exceeds the configured timeout.
	ErrShutdownTimeout = errors.New("shutdown timed out")
)

Sentinel errors for the daemon runner.

Functions

This section is empty.

Types

type Config

type Config struct {
	// ServiceName is the Windows service name.
	ServiceName string

	// DisplayName is the Windows service display name.
	DisplayName string

	// Port is the TCP port for fallback connections.
	// Use 0 for an ephemeral port.
	Port int

	// ConfigDir is the directory for configuration files.
	ConfigDir string

	// ShutdownTimeout is the maximum time to wait for graceful shutdown.
	// A zero value means no timeout.
	ShutdownTimeout time.Duration
}

Config holds the configuration for the daemon runner.

type Dependencies

type Dependencies struct {
	// ListenerFactory creates network listeners.
	// If nil, net.Listen is used.
	ListenerFactory func(network, address string) (net.Listener, error)

	// ShutdownFunc is called during shutdown to clean up resources.
	// If nil, no cleanup function is called.
	ShutdownFunc func() error
}

Dependencies holds the external dependencies for the daemon runner. This enables dependency injection for testing.

type Runner

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

Runner manages the daemon lifecycle.

func New

func New(config *Config, deps *Dependencies) *Runner

New creates a new daemon runner with the given configuration and dependencies. If config is nil, default values are used. If deps is nil, default dependencies (using net.Listen) are used.

func (*Runner) Config

func (r *Runner) Config() *Config

Config returns the runner's configuration.

func (*Runner) IsRunning

func (r *Runner) IsRunning() bool

IsRunning returns true if the daemon is currently running.

func (*Runner) Shutdown

func (r *Runner) Shutdown() error

Shutdown gracefully stops the daemon. Returns ErrNotRunning if the daemon is not running. Returns ErrShutdownTimeout if the shutdown function exceeds the configured timeout.

func (*Runner) Start

func (r *Runner) Start(ctx context.Context) error

Start begins the daemon and blocks until the context is canceled. Returns ErrAlreadyRunning if the daemon is already started.

Jump to

Keyboard shortcuts

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