Administration command-line interface
The administration command-line interface gives operators a direct way to change access state, inspect active bans, run commands supplied by plugins, and collect support data. Shared shell helpers support the same operational work by controlling services, checking health, and preparing runtime data across Linux and FreeBSD deployments.
Command-line role
The bwcli command is the operator-facing entry point. It passes requests to the installed BunkerWeb CLI, which then uses the configured management services and shared state stores rather than changing the gateway state on its own (src/common/helpers/bwcli#L1-L6).
Administrative commands
The CLI groups its work around access control, operational inspection, plugin actions, and support collection. Ban requests can be global or tied to a named service. Unban requests can remove an explicit ban and can also review or remove a related CrowdSec ban. The ban list combines information from the management API with available Redis state (src/…/main.py• L27-78, src/…/CLI.py• L475-591, src/…/CLI.py• L593-645, src/…/CLI.py• L647-824).
| Command | Operational purpose |
|---|---|
ban | Add a temporary or permanent global or service ban. |
unban | Remove a ban. CrowdSec changes require a review step before confirmation. |
bans | Show bans and CrowdSec leases across reachable sources. |
plugin_list | Show plugin commands available to the scheduler host. |
plugin | Run one command exposed by a selected plugin. |
support | Create a support bundle with operational data for diagnosis. |
Plugin command bridge
The plugin bridge extends the CLI without adding every plugin action to the main parser. The CLI reads the command map from shared plugin state, checks that the requested plugin command exists, and runs the plugin in its own command context. Plugin commands are a scheduler-host operation because they depend on the scheduler-side database and plugin files (src/…/CLI.py• L826-1035).
Support bundle
The support command collects a bounded view of the deployment for diagnosis. It includes environment and instance health data plus configuration, plugin, job, custom-configuration, log, and generated gateway-configuration information when those sources are available. Credentials are always redacted. IP addresses and service domains are anonymized by default, while each unavailable or partial section is recorded instead of preventing the rest of the bundle from being written (src/…/main.py• L73-95, src/…/CLI.py• L1037-1252).
The command is intended for the scheduler host because that host has the database and scheduler data needed for a complete bundle. It can write a zip file to disk or to redirected standard output, but it does not write binary output directly to an interactive terminal (src/…/CLI.py• L1037-1045, src/…/CLI.py• L1241-1252).
References: src/…/main.py• L73-95 src/…/CLI.py• L1037-1252
Execution context
The CLI must use the same configuration and state view as the services it controls. It resolves operator variables, then uses the initialized database for stored configuration and instance details. It also creates the configured Redis connection and API clients, so one CLI invocation can address local or multiple BunkerWeb instances (src/…/CLI.py• L51-80, src/…/CLI.py• L323-438). The support command can continue with a partial view when database setup is unavailable so that logs and other host data can still help diagnosis (src/…/main.py• L87-95, src/…/CLI.py• L342-373).
The main access-control flow is shown below.
flowchart LR
Operator[Operator] --> CLI[bwcli]
CLI --> Config[Operator configuration]
CLI --> DB[Shared database]
CLI --> API[Management API instances]
CLI --> Redis[Redis ban state]
API --> Result[Ban changes and ban views]
Redis --> Result
Config --> API
DB --> API
Configuration and state sources
The CLI gives operator-supplied variables priority over generated gateway variables. Operator files are merged in scheduler order, while generated values only fill gaps. When the database is present, normal commands require an initialized BunkerWeb schema before they load stored configuration. Support collection records an unavailable database and continues with the data it can read (src/…/CLI.py• L51-80, src/…/CLI.py• L171-189, src/…/CLI.py• L323-376, src/…/CLI.py• L1087-1105).
Instance coordination
Ban changes use the management API as the source of truth. A ban list can include API results from each configured instance and direct Redis results. Unban checks treat an incomplete response from any instance as an incomplete operation instead of assuming that an absent result means that no ban exists (src/…/CLI.py• L475-501, src/…/CLI.py• L550-591, src/…/CLI.py• L707-743).
Operational helper interfaces
The shared shell helpers provide the low-level operational contract used by startup scripts and service packages. They hide platform differences and turn process state, service state, and runtime file permissions into simple checks that deployment workflows can use.
Service control
The service helpers detect the host service manager and expose one set of actions for enable, disable, start, stop, restart, reload, and status. On Linux they use systemd. On FreeBSD they map the same actions to rc.d and its configuration files (src/…/utils.sh• L293-325, src/…/utils.sh• L327-578).
The same helper layer selects the available Python and NGINX programs, resolves the NGINX configuration directory, and can run a process as the nginx user with its service home. These shared choices keep administrative jobs aligned with the runtime environment (src/…/utils.sh• L9-120, src/…/utils.sh• L135-167).
Health checks
Health helpers distinguish process presence from service readiness. The gateway check requires a running NGINX process and accepts the gateway's ok or loading health state. Service checks for the API, UI, scheduler, and Autoconf require both a process marker and a service-owned healthy marker (src/…/healthcheck.sh• L3-30, src/…/healthcheck-api.sh• L3-15, src/…/healthcheck-ui.sh• L1-11, src/…/healthcheck-scheduler.sh• L1-11, src/…/healthcheck-autoconf.sh• L3-28).
The all-in-one health check applies those checks only to services enabled for that deployment. It also checks embedded Redis and CrowdSec when the container owns those services. This lets one readiness result reflect the selected runtime topology instead of requiring every optional service (src/…/healthcheck-all-in-one.sh• L3-137).
Runtime data readiness
The data helper prepares the shared /data area and checks the access needed by the nginx user. Writable locations hold changing state such as cache and library data. Configuration, plugin, and web locations must remain readable and searchable (src/…/data.sh• L7-47).
Change checklist
When these files or sections are changed, remember to consider these:
- Keep CLI parser names and dispatch paths aligned with the API operations and payload scope used for global and service bans.
- Keep variable-file precedence aligned with the scheduler so the CLI and scheduler select the same database.
- Keep plugin command metadata, plugin command paths, and the scheduler-only execution boundary aligned.
- Keep support-bundle refusal rules aligned with the deployment topology and scheduler availability.
- Keep support-bundle redaction, anonymization, section names, and size limits aligned with the data sources they describe.
- Keep service names and enablement behavior valid for both systemd and rc.d.
- Keep health marker names and optional-service gates aligned between individual probes and the all-in-one probe.
- Keep
/datadirectory permissions consistent with the users that read or write each runtime area.
Important failure modes
| Trigger | Consequence | Guard |
|---|---|---|
| The CLI resolves a database without the BunkerWeb schema. | Normal commands stop before they can use stored configuration. | Set the same database URI used by the scheduler and initialize it first. |
| The support command runs on a host without the scheduler role. | No support bundle is created. | Run it on the scheduler host or enable the scheduler in an all-in-one deployment. |
| No management API instance is reachable. | Ban, unban, and ban-list operations fail or return an incomplete result. | Keep the API enabled and healthy for every configured instance. |
| Redis is configured but cannot be reached. | Direct Redis ban data is unavailable and Redis-backed features are disabled for the CLI. | Check Redis connectivity and its selected host, port, and credentials. |
An unban finds a CrowdSec lease without -confirm. | The CLI shows the proposed change but does not apply the CrowdSec removal. | Review the preview and run the command again with confirmation. |
| A support bundle contains sensitive configuration or logs. | The bundle can expose credentials or identifying deployment data. | Keep credential redaction enabled and use anonymization unless exact values are required. |
| A plugin command is run where the scheduler database or plugin files are absent. | The CLI rejects the command. | Run plugin commands on the scheduler host with the plugin registered. |
| An enabled service lacks its process or healthy marker. | The deployment health check reports the service as unhealthy. | Restore the service and its readiness signal before relying on the deployment. |
Key files
| File | Why to read it |
|---|---|
src/common/helpers/bwcli | Shows the installed command wrapper and its handoff to the CLI entry point. |
| src/…/main.py | Defines the operator command surface, support-host checks, and exit behavior. |
| src/…/CLI.py | Shows how commands use configuration, databases, APIs, Redis, plugin state, and support data. |
| src/…/utils.sh | Defines shared environment, user, service-manager, and service-action helpers. |
| src/…/healthcheck.sh and src/…/healthcheck-all-in-one.sh | Define gateway and deployment-level readiness decisions. |
| src/…/healthcheck-api.sh, healthcheck-ui.sh, healthcheck-scheduler.sh, and healthcheck-autoconf.sh | Define readiness signals for the optional management services. |
| src/…/data.sh | Defines the shared runtime data layout and permission checks. |
Related pages: Management services, Management API, Web user interface.