control

package
v0.0.0-...-d22ae78 Latest Latest
Warning

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

Go to latest
Published: Aug 27, 2026 License: AGPL-3.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	RunDir             = "/run/nic"
	PIDPath            = RunDir + "/nic.pid"
	AppliedConfigPath  = RunDir + "/applied-config.json"
	PendingConfigPath  = RunDir + "/pending-config.json"
	BaseStatePath      = RunDir + "/base-state.json"
	ReloadRequestPath  = RunDir + "/reload-request.json"
	ReloadResponsePath = RunDir + "/reload-response.json"
	ReloadLockPath     = RunDir + "/reload.lock"
	RevertResponsePath = RunDir + "/revert-response.json"
)
View Source
var (
	ErrNotRunning       = errors.New("nic daemon is not running")
	ErrReloadInProgress = errors.New("nic reload is already in progress")
)

Functions

func ClaimDaemon

func ClaimDaemon() (func(), error)

ClaimDaemon atomically claims the daemon PID file. Stale records are removed only after the recorded process start time no longer matches.

func ClaimReload

func ClaimReload() (func(), error)

ClaimReload serializes CLI reload requests. A file lock is automatically released if the requesting process exits, so it cannot leave a stale lock that blocks future network changes.

func IsDaemonRunning

func IsDaemonRunning() bool

func NewRequestID

func NewRequestID() string

func ProcessExecutableName

func ProcessExecutableName(pid int) (string, error)

func ProcessRecordIsLive

func ProcessRecordIsLive(record PIDRecord) bool

func ReadJSON

func ReadJSON(path string, value any) error

func SignalDaemon

func SignalDaemon(sig syscall.Signal) error

func SignalProcessRecord

func SignalProcessRecord(record PIDRecord, sig syscall.Signal) error

func StopDaemon

func StopDaemon(timeout time.Duration) (bool, error)

func TerminateProcessRecord

func TerminateProcessRecord(record PIDRecord, sig syscall.Signal, timeout time.Duration) error

TerminateProcessRecord signals a tracked process and waits until it has actually exited. Callers must keep their PID/configuration records when this returns an error so a live process cannot be replaced by a second instance.

func WaitProcessRecord

func WaitProcessRecord(record PIDRecord, timeout time.Duration) error

WaitProcessRecord waits for the exact recorded process to exit. The start time check prevents a recycled PID from being mistaken for the process that nic originally launched.

func WaitResponse

func WaitResponse(path, id string, timeout time.Duration) error

func WriteJSONAtomic

func WriteJSONAtomic(path string, value any, mode os.FileMode) error

Types

type PIDRecord

type PIDRecord struct {
	PID       int    `json:"pid"`
	StartTime string `json:"start_time"`
}

func DaemonRecord

func DaemonRecord() (PIDRecord, error)

DaemonRecord returns the identity of the currently running daemon. The process start time makes the identity safe even if the kernel later reuses its PID.

func ReadProcessRecord

func ReadProcessRecord(path string) (PIDRecord, error)

func RecordForPID

func RecordForPID(pid int) (PIDRecord, error)

type ReloadRequest

type ReloadRequest struct {
	ID           string    `json:"id"`
	ConfigPath   string    `json:"config_path"`
	SnapshotPath string    `json:"snapshot_path,omitempty"`
	Timeout      int       `json:"timeout"`
	Daemon       PIDRecord `json:"daemon"`
}

type Response

type Response struct {
	ID    string `json:"id,omitempty"`
	Error string `json:"error,omitempty"`
}

Jump to

Keyboard shortcuts

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