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
- func DefaultModSecurityModule(bin string) string
- func ParseModuleFeatures(v string) []string
- func ParseVersion(out string) string
- type Config
- type Nginx
- func (n *Nginx) ModuleFeatures(ctx context.Context) ([]string, error)
- func (n *Nginx) Reload(ctx context.Context) error
- func (n *Nginx) Run(ctx context.Context) error
- func (n *Nginx) Running() bool
- func (n *Nginx) Started() <-chan struct{}
- func (n *Nginx) Test(ctx context.Context, conf string) error
- func (n *Nginx) Version(ctx context.Context) (string, error)
Constants ¶
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.
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 ¶
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 ¶
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 ¶
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 (*Nginx) ModuleFeatures ¶
ModuleFeatures returns the features of the static modules compiled into the binary (ParseModuleFeatures of `nginx -V`).
func (*Nginx) Reload ¶
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 ¶
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 ¶
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.