Introducing a new way to review your PRs.

Read the announcement

bunkerity / bunkerweb

🛡️ Open-source and cloud-native Web Application Firewall (WAF)

View on GitHub

19 documents · Updated Nov 23, 2026

docs / linux-packaging

Linux packaging and service installation

Linux packaging turns a platform-specific build image into an installable BunkerWeb package. The package carries the application, its run-time data, system service units, and the scripts that make fresh installs, upgrades, and removal safe on supported Linux systems. For the wider release model, see Distribution and deployment; for container-based alternatives, see Container runtime topologies.

Packaging model

The build uses Docker images as repeatable packaging environments. Each image prepares the platform libraries and language tools, assembles BunkerWeb, and starts with the correct package recipe to produce either a Debian package or an RPM package. src/…/package.sh selects the image from the distribution name, selects deb or rpm, passes the requested architecture, and gives the output a versioned file name. (src/linux/package.sh#L16-L50)

The build supports two package families:

Package familyPlatform groupPackage result
DEBUbuntu and Debian-family targetsA versioned .deb package
RPMFedora, RHEL, and related targetsA versioned .rpm package

The package build keeps the platform choice in the image and recipe pair. This lets the same application payload use the dependency names, repository setup, and package rules required by each Linux family.

The overall build flow is:

flowchart LR
    A[Platform and architecture] --> B[Build image]
    B --> C[Platform dependencies]
    C --> D[BunkerWeb payload]
    D --> E[Package recipe]
    E --> F[DEB or RPM artifact]

Platform packaging inputs

The Dockerfiles define the build environment and the final package staging area. They install the platform toolchain, obtain the supported Nginx package, build or install BunkerWeb dependencies, collect the application payload, and place Linux-specific files into the package workspace. The Debian Bookworm image is a pinned two-stage DEB build: it verifies the Nginx signing key, installs the exact Nginx version used by the package, bundles Python dependencies, and prepares optional web asset minification before the package is created. (src/linux/Dockerfile-debian-bookworm#L1-L24, src/linux/Dockerfile-debian-bookworm#L26-L62, src/linux/Dockerfile-debian-bookworm#L152-L189)

Each target has a matching Dockerfile and FPM input. The repository files for Nginx sources and signing keys provide the platform package source, while the Rocky repository files and keys support RHEL-family builds. These inputs keep package creation tied to known platform versions instead of relying on the host that runs the build. (src/linux/rocky-9.repo#L1-L20, src/linux/RPM-GPG-KEY-Rocky-9#L1-L1)

The build also prepares static assets and dependency bundles before packaging. It installs the application dependencies, applies required patches, compresses the dependency directory for later installation, and can minify web assets in the image. The result is a package that can install the application without repeating the full build on the target host. (src/linux/Dockerfile-debian-bookworm#L34-L62, src/linux/Dockerfile-debian-bookworm#L81-L150)

Package recipes

The FPM recipe describes the package contract. It names the package, records its version and architecture, declares the platform run-time dependencies, connects package lifecycle hooks, and maps application, configuration, state, log, cache, and systemd paths into the installed system. The Ubuntu recipe defines the DEB variant, while the RHEL recipe defines the RPM variant with equivalent roles and platform-specific dependency names. (src/linux/fpm-ubuntu#L1-L14; src/linux/fpm-rhel-9#L1-L13)

src/…/fpm.sh supplies the version and architecture at package-build time. It also applies the selected package format and compression policy before writing the artifact into the build output volume. (src/linux/fpm.sh#L3-L30)

References: src/…/fpm-ubuntu• L1-14 src/…/fpm-rhel-9• L1-13 src/…/fpm.sh• L3-30

Package contents

The installed package separates immutable application files from host-owned configuration and state. Application code is placed under /usr/share/bunkerweb, the CLI is exposed as /usr/bin/bwcli, configuration is placed under /etc/bunkerweb, and run-time, cache, log, and database data use their own /var paths. The package also installs the service units and log rotation policy that connect the application to the host. (src/linux/fpm-ubuntu#L10-L14; src/linux/fpm-rhel-9#L10-L13)

The post-install setup expands the dependency bundle and applies a least-privilege layout. The nginx account owns writable run-time paths, while the application tree stays read-only to the service. It also repairs compatible legacy lock and secret-file permissions without replacing files that may be in use. (src/linux/scripts/postinstall.sh#L20-L68)

References: src/…/fpm-ubuntu• L10-14 src/…/fpm-rhel-9• L10-13 src/…/postinstall.sh• L20-68

Service installation

The package installs four systemd units that split the Linux deployment into the protected traffic path, configuration scheduler, management UI, and optional API. All units start after the network is available, restart after an unexpected exit, write to the system journal, and delegate start, stop, and reload work to a role-specific support script. (src/linux/bunkerweb.service#L1-L20; src/linux/bunkerweb-scheduler.service#L1-L20; src/linux/bunkerweb-ui.service#L1-L20; src/linux/bunkerweb-api.service#L1-L20)

UnitSystem roleDefault activation intent
bunkerweb.serviceRuns the Nginx-based BunkerWeb traffic serviceStandalone or worker deployments
bunkerweb-scheduler.serviceBuilds and updates service configuration and database stateStandalone or manager deployments
bunkerweb-ui.serviceServes the management interfaceStandalone or manager deployments
bunkerweb-api.serviceServes the API interfaceOnly when explicitly enabled

The units are deliberately thin. Their systemd contract is stable while the support scripts own process setup, environment loading, graceful stop behavior, and reload rules. (src/linux/bunkerweb.service#L6-L20; src/linux/bunkerweb-scheduler.service#L6-L20)

Service topology

The installer resolves a topology from manager and worker modes or from explicit service flags. A topology is the intended set of enabled services for the host. On a fresh install or an explicit topology change, the installer enables and starts the intended units, disables units that do not belong, and records the resolved install type for later upgrades. On a plain upgrade with no topology signal, it avoids changing ambiguous enabled-but-stopped units. (src/linux/scripts/postinstall.sh#L147-L171, src/linux/scripts/postinstall.sh#L173-L347)

The service decision flow is:

flowchart TD
    A[Package install or upgrade] --> B[Resolve declared topology]
    B --> C{Fresh install or explicit mode?}
    C -->|Yes| D[Enable and start intended units]
    C -->|Yes| E[Disable unwanted units]
    C -->|No| F[Preserve ambiguous stopped units]
    D --> G[Persist install type]
    E --> G
    F --> H[Let upgrade detection infer state]

References: src/…/postinstall.sh• L147-171 src/…/postinstall.sh• L173-347

Service support scripts

The support scripts adapt each unit to its process role. The main service prepares temporary configuration and starts Nginx. The scheduler prepares its environment and checks database migrations before it runs jobs. The UI and API scripts create their local environment files and run their web processes under the nginx account. (src/linux/scripts/start.sh#L60-L91, src/linux/scripts/bunkerweb-scheduler.sh#L27-L68, src/linux/scripts/bunkerweb-scheduler.sh#L128-L265, src/linux/scripts/bunkerweb-ui.sh#L37-L159, src/linux/scripts/bunkerweb-api.sh#L37-L245)

These scripts also define the process boundary used by systemd. They create PID, temporary, and log paths when needed. They read role-specific settings with shared defaults and provide controlled stop and reload actions. This keeps service behavior consistent whether an operator uses systemd or invokes a support script during package actions. (src/linux/scripts/start.sh#L273-L333, src/linux/scripts/bunkerweb-scheduler.sh#L271-L338, src/linux/scripts/bunkerweb-ui.sh#L162-L202, src/linux/scripts/bunkerweb-api.sh#L247-L272)

References: src/…/start.sh• L60-91 src/…/bunkerweb-scheduler.sh• L27-68 src/…/bunkerweb-scheduler.sh• L128-265 src/…/bunkerweb-ui.sh• L37-159 src/…/bunkerweb-api.sh• L37-245

Installation support

misc/install-bunkerweb.sh is the operator-facing entry point for native Linux installation. It detects the distribution family and architecture, chooses the matching package tools, and maps an installation type to the services that should run. It can also choose the Docker deployment path; that path belongs to Container runtime topologies, while this page follows the host-package path. (misc/install-bunkerweb.sh#L3520-L3621, misc/install-bunkerweb.sh#L4426-L4470)

The native installer supports full, manager, worker, scheduler-only, UI-only, and API-only topologies. On a fresh install it runs the host preparation, optional integration, configuration, package, and service phases in order. It stores a protected phase snapshot so an interrupted install can resume without asking for the same choices again. (misc/install-bunkerweb.sh#L298-L343, misc/install-bunkerweb.sh#L9468-L9532, misc/install-bunkerweb.sh#L9650-L9829)

Upgrade orchestration

An upgrade first identifies the installed version and service topology. When a scheduler-backed installation is present, the installer can create a pre-upgrade backup, stop active services in a controlled order, install the new package with apt or dnf, and start the services that were active before the upgrade. The package post-install hook then restores transaction data and completes topology-aware service handling. (misc/install-bunkerweb.sh#L9183-L9257, misc/install-bunkerweb.sh#L9274-L9336, misc/install-bunkerweb.sh#L9352-L9465)

The installer keeps Nginx aligned with the BunkerWeb package that was built against it. Its release-to-Nginx mapping prevents a host upgrade from loading BunkerWeb modules with an incompatible Nginx version. (misc/install-bunkerweb.sh#L123-L155)

References: misc/install-bunkerweb.sh• L3520-3621 misc/install-bunkerweb.sh• L4426-4470 misc/install-bunkerweb.sh• L9183-9257 misc/install-bunkerweb.sh• L9274-9336 misc/install-bunkerweb.sh• L9352-9465

Installation lifecycle

Package hooks protect host state across installation, upgrade, and removal. Before installation, the package backs up the existing Nginx configuration and can request scheduler enablement for older installations. After installation, it restores upgrade backups, refreshes systemd, applies permissions, and aligns the active services with the selected topology. (src/linux/scripts/beforeInstall.sh#L18-L30; src/linux/scripts/postinstall.sh#L70-L104, src/linux/scripts/postinstall.sh#L141-L171)

Upgrade handling preserves configuration and database data in /var/backups/bunkerweb with restricted permissions. The post-install step restores only the transaction snapshot for the current package operation, validates the SQLite snapshot when present, and marks the restore complete before service activation. (src/linux/scripts/afterRemoveDEB.sh#L157-L197, src/linux/scripts/afterRemoveRPM.sh#L146-L185, src/linux/scripts/postinstall.sh#L70-L124)

Removal stops Nginx and BunkerWeb units, reloads systemd, and removes application and transient files. Normal removal keeps configuration and persistent data so a later install can reuse them. Debian purge removes those paths as well, while RPM removal leaves the final purge decision to the administrator. (src/linux/scripts/afterRemoveDEB.sh#L76-L117, src/linux/scripts/afterRemoveRPM.sh#L76-L105)

Change checklist

When these files or sections are changed, remember to consider these:

  • Keep every supported Dockerfile paired with the correct fpm-* recipe so its package format, dependencies, lifecycle hooks, and payload paths agree.
  • Keep the Nginx version in each package image, its FPM dependency, and the installer release-to-Nginx map synchronized.
  • Keep all four service unit Exec* paths aligned with the support scripts copied into the package.
  • Keep topology names, service flags, the install-type marker, and the enable/disable rules consistent so upgrades do not infer the wrong host role.
  • Keep installer phase names and saved state variables aligned so a resumed install does not lose a choice that changes package or service behavior.
  • Keep upgrade backup paths and restore paths identical across the DEB and RPM removal hooks and postinstall.sh.
  • Keep package-owned directories, ownership rules, and preserved removal paths aligned so upgrades retain configuration and state without leaving unusable run-time paths.

Important failure modes

TriggerConsequenceGuard
A platform image and FPM recipe use different dependency names or versionsThe package cannot resolve dependencies or installs an unsupported run-time stackTreat each Dockerfile and matching fpm-* file as one platform contract
The installer selects an Nginx version different from the one used to build the package modulesNginx can fail to load the BunkerWeb modulesKeep the Dockerfile pin and installer release map synchronized
A service unit points to a missing support scriptsystemd cannot start, stop, or reload that serviceInstall unit files and scripts together through the package recipe
A saved install state is changed, exposed, or read after its schema is staleA resumed install can use unsafe or incompatible choicesUse the protected state directory, strict file mode, schema check, and age check
An upgrade backup is not copied with restricted permissionsConfiguration secrets or database contents can be exposedStore backups under /var/backups/bunkerweb with mode 0600
An explicit topology is not recorded or appliedA later upgrade can enable the wrong service setResolve the topology and write INSTALL_TYPE only when intent is declared
Configuration generation, database validation, or service restart fails during installationThe traffic service or scheduler stays down with old or incomplete stateStop on required hook failures and restore only a validated transaction snapshot

Key files

FileWhy to read it
src/…/package.shShows how a requested distribution and architecture become a package artifact.
src/linux/Dockerfile-debian-bookwormShows the pinned Debian DEB build inputs, dependency bundle, asset preparation, and package staging.
src/linux/Dockerfile-ubuntuIllustrates the Debian-family image build and final package staging.
src/linux/Dockerfile-rhel-9Illustrates the RPM-family image build and platform-specific inputs.
src/linux/fpm-ubuntuDefines the DEB dependencies, hooks, and installed paths.
src/linux/fpm-rhel-9Defines the RPM equivalent of the package contract.
src/…/postinstall.shExplains dependency unpacking, permissions, upgrade restore, service activation, and topology handling.
misc/install-bunkerweb.shShows native platform selection, installation types, resumable phases, and upgrade orchestration.
src/linux/bunkerweb.serviceDefines the systemd contract for the main traffic service.
src/linux/bunkerweb-scheduler.serviceDefines the systemd contract for configuration and database work.
src/linux/bunkerweb-ui.serviceDefines the systemd contract for the management UI.
src/linux/bunkerweb-api.serviceDefines the systemd contract for the optional API.
src/…/afterRemoveDEB.shShows Debian removal, purge, and upgrade backup behavior.
src/…/afterRemoveRPM.shShows RPM removal and upgrade backup behavior.