daemon

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jan 5, 2026 License: MIT Imports: 15 Imported by: 0

Documentation

Overview

Package daemon provides daemon lifecycle management for omniproxyd.

Index

Constants

This section is empty.

Variables

View Source
var (
	DefaultDir        = filepath.Join(os.Getenv("HOME"), ".omniproxy")
	DefaultPIDFile    = filepath.Join(DefaultDir, "omniproxyd.pid")
	DefaultSocketPath = filepath.Join(DefaultDir, "omniproxyd.sock")
	DefaultLogFile    = filepath.Join(DefaultDir, "omniproxyd.log")
)

Default paths for daemon files.

Functions

func IsRunning

func IsRunning(pidFile string) (bool, int, error)

IsRunning checks if the daemon is running.

func StartBackground

func StartBackground(args []string) error

StartBackground starts the daemon in the background.

func StopByPID

func StopByPID(pidFile string) error

StopByPID stops the daemon by sending SIGTERM to the PID.

Types

type Client

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

Client provides methods to communicate with the daemon.

func NewClient

func NewClient(socketPath string) *Client

NewClient creates a new daemon client.

func (*Client) GetStatus

func (c *Client) GetStatus() (*Status, error)

GetStatus retrieves the daemon status.

func (*Client) Reload

func (c *Client) Reload() error

Reload sends a reload request to the daemon.

func (*Client) Stop

func (c *Client) Stop() error

Stop sends a stop request to the daemon.

type Config

type Config struct {
	PIDFile    string
	SocketPath string
	LogFile    string
	ProxyPort  int
	Host       string
	Database   string
	Version    string
}

Config holds daemon configuration.

func DefaultConfig

func DefaultConfig() *Config

DefaultConfig returns default daemon configuration.

type Daemon

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

Daemon manages the proxy daemon lifecycle.

func New

func New(cfg *Config) *Daemon

New creates a new daemon instance.

func (*Daemon) IncrementRequests

func (d *Daemon) IncrementRequests()

IncrementRequests increments the request counter.

func (*Daemon) SetCallbacks

func (d *Daemon) SetCallbacks(onStart, onStop, onReload func() error)

SetCallbacks sets the daemon lifecycle callbacks.

func (*Daemon) SetTrafficQuerier

func (d *Daemon) SetTrafficQuerier(tq backend.TrafficQuerier)

SetTrafficQuerier sets the traffic querier for the /traffic endpoint.

func (*Daemon) Start

func (d *Daemon) Start(ctx context.Context) error

Start starts the daemon control server.

func (*Daemon) Status

func (d *Daemon) Status() *Status

Status returns the current daemon status.

func (*Daemon) Stop

func (d *Daemon) Stop(ctx context.Context) error

Stop stops the daemon.

func (*Daemon) Wait

func (d *Daemon) Wait()

Wait blocks until the daemon stops.

type Status

type Status struct {
	Running     bool      `json:"running"`
	PID         int       `json:"pid,omitempty"`
	StartTime   time.Time `json:"start_time,omitempty"`
	Uptime      string    `json:"uptime,omitempty"`
	ProxyPort   int       `json:"proxy_port,omitempty"`
	MetricsPort int       `json:"metrics_port,omitempty"`
	Version     string    `json:"version,omitempty"`
	Database    string    `json:"database,omitempty"`
	Requests    int64     `json:"requests,omitempty"`
}

Status represents the daemon status.

type TrafficResponse

type TrafficResponse struct {
	Records []*backend.TrafficRecord `json:"records"`
	Total   int64                    `json:"total"`
	Limit   int                      `json:"limit"`
	Offset  int                      `json:"offset"`
}

TrafficResponse is the response format for the /traffic endpoint.

Jump to

Keyboard shortcuts

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