engine

package
v1.9.0 Latest Latest
Warning

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

Go to latest
Published: Nov 19, 2026 License: AGPL-3.0 Imports: 16 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package engine controls the OpenResty (nginx) process: configuration tests, reloads and, in managed mode, supervising nginx as a child process of the agent.

Managed mode (--manage-nginx, used by the container image and the systemd unit) runs `openresty -g 'daemon off;'` as a child, reloads it with SIGHUP, restarts it with exponential backoff if it dies, and stops it gracefully (SIGQUIT, then SIGKILL after a timeout) when the agent shuts down. Unmanaged mode expects nginx to be run by someone else and reloads it with `-s reload` (pid file).

Index

Constants

View Source
const (
	FeatureBrotli      = "brotli-v1"
	FeatureZstd        = "zstd-v1"
	FeatureModSecurity = "modsecurity-v1"
)

Features of the optional OpenResty modules (see configir): Brotli and Zstandard are static modules of edgeweir-openresty; ModSecurity is a dynamic module the node probes separately.

View Source
const ModSecurityModuleFile = "ngx_http_modsecurity_module.so"

ModSecurityModuleFile is the file name of the ModSecurity-nginx dynamic module.

Variables

This section is empty.

Functions

func DefaultModSecurityModule

func DefaultModSecurityModule(bin string) string

DefaultModSecurityModule returns where edgeweir-openresty installs the ModSecurity module relative to the nginx binary bin (resolved through PATH and symlinks): <prefix>/modules next to <prefix>/nginx/sbin/nginx. It returns "" when there is no such file.

func ParseModuleFeatures

func ParseModuleFeatures(v string) []string

ParseModuleFeatures returns the features of the static modules named in the configure arguments of `nginx -V` output: ngx_brotli (brotli-v1) and zstd-nginx-module (zstd-v1). Only --add-module counts: a dynamic module is not part of the binary.

func ParseVersion

func ParseVersion(out string) string

ParseVersion extracts the version from `nginx -v` output.

Types

type Config

type Config struct {
	// Bin is the openresty/nginx binary (looked up in PATH if relative).
	Bin string
	// Prefix is the nginx prefix directory (-p).
	Prefix string
	// Conf is the absolute path of the main configuration file (-c).
	Conf string
	// Managed runs nginx as a supervised child process.
	Managed bool
	// StaleSockets are unix sockets removed before nginx starts (left over
	// after a crash they would make bind() fail).
	StaleSockets []string
	// StaleSocketGlobs name more of them by pattern.
	StaleSocketGlobs []string
	// StopTimeout bounds graceful shutdown before SIGKILL (default 8s).
	StopTimeout time.Duration
	Logger      *slog.Logger
	// LogSink receives OpenResty's error log messages of level warn and
	// above as node log entries (nodelog.ParseNginx); nil: none.
	LogSink func(nodelog.Entry)
	// DebugSink receives every error log message of every level
	// (nodelog.ParseNginxDebug) for the debug log ring; nil: none.
	DebugSink func(nodelog.Entry)
}

Config configures an Nginx engine.

type Nginx

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

Nginx implements the engine for OpenResty.

func New

func New(cfg Config) *Nginx

New returns an engine for cfg.

func (*Nginx) ModuleFeatures

func (n *Nginx) ModuleFeatures(ctx context.Context) ([]string, error)

ModuleFeatures returns the features of the static modules compiled into the binary (ParseModuleFeatures of `nginx -V`).

func (*Nginx) Reload

func (n *Nginx) Reload(ctx context.Context) error

Reload makes nginx pick up the configuration file. In managed mode it sends SIGHUP to the child, or starts nginx if it is not running.

func (*Nginx) Run

func (n *Nginx) Run(ctx context.Context) error

Run supervises the managed child until ctx is done. It waits for the first Reload before starting nginx (the agent tests the configuration first). In unmanaged mode it just blocks.

func (*Nginx) Running

func (n *Nginx) Running() bool

Running reports whether the managed child is running. In unmanaged mode it always returns true (the process is not ours to observe).

func (*Nginx) Started

func (n *Nginx) Started() <-chan struct{}

Started receives a value every time the managed child (re)starts; the agent re-pushes the site table then, because the shared dicts are empty.

func (*Nginx) Test

func (n *Nginx) Test(ctx context.Context, conf string) error

Test runs `openresty -t` against conf. The returned error carries nginx's own diagnostics, which are reported to the console verbatim.

func (*Nginx) Version

func (n *Nginx) Version(ctx context.Context) (string, error)

Version returns the engine version, e.g. "1.31.1.1" for "nginx version: openresty/1.31.1.1".

Jump to

Keyboard shortcuts

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