Native install: mandatory install directory, UI delivered from the repository
- install.sh always asks for the install directory (--prefix or a prompt with confirmation, no default); refuses system directories, the repository checkout itself, paths inside/containing it and non-empty directories (a resumed install is allowed). A preflight refusal says nothing was changed. - UI is part of the repository: committed build in deploy/ui-dist with SOURCE_HASH and a staleness guard (check-ui.sh, loud warning). install.sh and update.sh resolve the UI: --ui-dist FILE|DIR, --build-ui, committed build; install stops without a UI unless --no-ui. update.sh swaps the UI when its hash differs from the installed one (.ui-source-hash). - build-ui.sh: --docker, --local (host Node >= 20.19, temporary copy), --node-download (portable Node, SHA-256 verified), --publish. - Verified on Alpine 3.23: install without UI options installs the real UI; local build equals the Docker build; update skips an unchanged UI and warns on a stale build. --node-download is untested (needs network). - Docs: Scenario 2 guide, change summary, plan, README. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
4abd2044f0
commit
8371d889a4
31 files changed
+920
-114
No files matched your search
@@ -1,10 +1,11 @@
|
||||
# Scenario 2: installation as system services (no containers)
|
||||
|
||||
Install and update on **Alpine (OpenRC)**, **Debian** and **Ubuntu** (systemd) with the scripts in `deploy/native/`. Nothing runs in a container, nothing needs Node on the host.
|
||||
Install and update on **Alpine (OpenRC)**, **Debian** and **Ubuntu** (systemd) with the scripts in `deploy/native/`. Nothing runs in a container. The web UI is part of the repository (`deploy/ui-dist`) and is installed automatically, so the host needs no Node.
|
||||
|
||||
| Script | Purpose |
|
||||
|---|---|
|
||||
| `deploy/native/build-ui.sh` | builds the web UI in a Node 20 container into `ui-dist.tar.gz` (on any machine with Docker) |
|
||||
| `deploy/native/build-ui.sh` | builds the web UI (Docker, or the local Node without a container) into a tarball and/or into the repository (`--publish`) |
|
||||
| `deploy/native/check-ui.sh` | checks that the committed UI build `deploy/ui-dist` matches the `APP_UI` sources (exit 1 when stale) |
|
||||
| `deploy/native/install.sh` | first installation: packages, user, code, virtualenvs, configuration, services, nginx with TLS, health checks |
|
||||
| `deploy/native/update.sh` | update with a verified backup, a separate database migration step and automatic rollback; `--rollback` for a manual one |
|
||||
| `deploy/native/backup.sh` / `restore.sh` | stand-alone backup (cron friendly) and restore |
|
||||
@@ -41,31 +42,75 @@ Another version of these systems is refused with a warning unless you pass `--fo
|
||||
- Free space: about 1 GB for the code and virtualenvs (the script checks it), plus room for the backups.
|
||||
- Python 3.9 or newer (Alpine 3.23: 3.12, Debian 12: 3.11, Ubuntu 24.04: 3.12).
|
||||
- Free TCP ports `5001`, `8000` (on `127.0.0.1`) and the HTTPS port (default `8088`).
|
||||
- The UI archive (see below). **The host needs no Node.js.**
|
||||
- A UI build: the clone contains one (`deploy/ui-dist`, see below). **The host needs no Node.js** unless you choose `--build-ui`.
|
||||
- GNU tar (on Alpine the package `tar`; the installer adds it).
|
||||
|
||||
## Building the UI (any machine with Docker)
|
||||
## The web UI
|
||||
|
||||
```bash
|
||||
deploy/native/build-ui.sh # -> deploy/native/ui-dist.tar.gz
|
||||
deploy/native/build-ui.sh -o /tmp/ui.tar.gz # another output file
|
||||
OVPMON_NODE_IMAGE=node:20-alpine deploy/native/build-ui.sh --image node:22-alpine
|
||||
The UI is built from `APP_UI` (Vue/Vite). The repository carries a ready build in `deploy/ui-dist/` together with `SOURCE_HASH`, a SHA-256 over the UI sources it was built from (`APP_UI/src`, `public`, `index.html`, `package.json`, `package-lock.json`, `vite.config.js`, `jsconfig.json`). `install.sh` and `update.sh` find the UI themselves. The directory is outside `APP_UI`, so the container builds are not affected.
|
||||
|
||||
### Three ways to get the UI onto a host
|
||||
|
||||
| Way | Option | When |
|
||||
|---|---|---|
|
||||
| Committed build | none (automatic) | the normal case: `git clone`, `install.sh`, done; no Node, no Docker |
|
||||
| Build on the host | `--build-ui` | the committed build is stale or missing; builds from `APP_UI` now with Docker (when its daemon works) or the host's Node 20.19+ |
|
||||
| Build elsewhere | `--ui-dist FILE\|DIR` | a tarball from `build-ui.sh` or a directory with `index.html`, for example from a CI job or another machine |
|
||||
|
||||
Order used by `install.sh` and `update.sh`: **1.** `--ui-dist` (explicit, always installed), **2.** `--build-ui` (always builds fresh from the sources), **3.** the committed `deploy/ui-dist` of the checkout (automatic), **4.** nothing found: `install.sh` **stops** (it lists the ways out) unless `--no-ui` is given (a placeholder page on purpose); `update.sh` keeps the installed UI. `install.sh` also still accepts `deploy/native/ui-dist.tar.gz` as a last resort below the committed directory. `--ui-dist` and `--build-ui` exclude each other.
|
||||
|
||||
The installed web root records the hash it came from in `/var/www/ovpmon/.ui-source-hash` (`unknown` for archives that were not made by `build-ui.sh`). `update.sh` compares it with the `SOURCE_HASH` of the repository build: equal, the UI is not replaced (and it says so); different or missing (for example a host installed with `--no-ui`), the new UI is staged in phase 3 and swapped in phase 6, with the rest of the update, so it is part of the backup and the automatic rollback. The UI source is decided after `git pull`, so a pulled new build is used in the same run. The old UI is in the backup.
|
||||
|
||||
### Staleness guard
|
||||
|
||||
When the hash of the current `APP_UI` sources differs from `SOURCE_HASH`, the committed build is **older than the sources** (someone changed the UI and did not refresh the build). `install.sh` and `update.sh` then print a loud warning with the two hashes and the remedy, and still use the committed build (it works, it only lacks the latest UI changes). A host that needs the current UI adds `--build-ui`. A build without a valid `SOURCE_HASH` counts as stale.
|
||||
|
||||
### Maintainer routine
|
||||
|
||||
After every change in `APP_UI` (or its `package*.json`, `vite.config.js`), **before committing**:
|
||||
|
||||
```sh
|
||||
deploy/native/build-ui.sh --publish # rebuilds deploy/ui-dist/ and SOURCE_HASH from the current sources
|
||||
deploy/native/check-ui.sh # prints fresh | stale | missing; exit 0 | 1 | 2
|
||||
git add APP_UI deploy/ui-dist
|
||||
```
|
||||
|
||||
The script runs `npm ci` (or `npm install` without a lock file) and `npm run build` in `node:20-alpine`. `APP_UI` is mounted read-only and copied inside the container, so **nothing is written into the source tree** except the output file. The archive holds the content of `dist/` with `index.html` at its top level. Without Docker the script stops with a clear message; you can then build elsewhere (`npm install && npm run build` in `APP_UI`) and pack `dist/` yourself (`tar -czf ui-dist.tar.gz -C dist .`).
|
||||
`check-ui.sh` also fits a release checklist or a CI step (it changes nothing). `--publish` replaces the content of `deploy/ui-dist/` by a move (the old directory is only deleted after the new one is in place).
|
||||
|
||||
Copy the archive to the target host together with the repository checkout and pass it with `--ui-dist FILE`. `install.sh` also picks up `deploy/native/ui-dist.tar.gz` automatically when it exists; `update.sh` uses a UI archive only when you pass `--ui-dist` explicitly (it never reinstalls a stale one).
|
||||
### build-ui.sh
|
||||
|
||||
```sh
|
||||
deploy/native/build-ui.sh # Docker if it works, otherwise local Node -> deploy/native/ui-dist.tar.gz
|
||||
deploy/native/build-ui.sh --docker # node:20-alpine container (OVPMON_NODE_IMAGE or --image to change)
|
||||
deploy/native/build-ui.sh --local # Node >= 20.19 and npm of this machine, no container
|
||||
deploy/native/build-ui.sh --local --node-download # temporary official Node 20, deleted after the build
|
||||
deploy/native/build-ui.sh --publish # refresh deploy/ui-dist/ in the repository
|
||||
deploy/native/build-ui.sh -o /tmp/ui.tar.gz # tarball for another host (also with --publish)
|
||||
deploy/native/build-ui.sh --check # only check that the builder is usable
|
||||
```
|
||||
|
||||
Without `--docker`/`--local` the script uses Docker when its daemon answers, otherwise the local Node. The tarball holds the content of `dist/` and `SOURCE_HASH`. **Nothing is written into the source tree**: a container sees `APP_UI` read-only; `--local` copies it (without `node_modules` and `dist`) into a temporary directory and runs `npm ci` there (`npm install` without a lock file), so the repository gets no `node_modules` and no `dist`.
|
||||
|
||||
`--local` needs Node 20.19 or newer with npm. When it is missing or too old the script prints what to do and stops:
|
||||
|
||||
| System | What to do |
|
||||
|---|---|
|
||||
| Alpine | `apk add nodejs npm` (check `node --version` afterwards) |
|
||||
| Debian / Ubuntu | the distribution's Node is usually too old (Debian 12 and Ubuntu 24.04 ship Node 18): add `--node-download` (needs `apt-get install -y curl xz-utils`), or install Node 20+ with npm from nodejs.org / NodeSource |
|
||||
| anything else | Node 20.19+ from nodejs.org, or build with `--docker` on a machine with Docker |
|
||||
|
||||
`--node-download` fetches `SHASUMS256.txt` from `https://nodejs.org/dist/latest-v20.x/`, picks `node-v20.*-linux-<x64|arm64>.tar.xz`, verifies its SHA-256, unpacks it into a temporary directory (npm cache included), builds with it and deletes everything; nothing is installed on the host. glibc systems only: on Alpine (musl) it refuses and points to `apk add nodejs npm`. It needs `curl`, `tar`, `xz` and access to nodejs.org (`OVPMON_NODE_MAJOR` selects another major version).
|
||||
|
||||
## Install
|
||||
|
||||
Clone the repository on the target host, put the UI archive next to the scripts and run, as root:
|
||||
Clone the repository on the target host (anywhere **outside** the install directory: the checkout is only the source, e.g. `/root/ovpmon-src`) and run, as root. The UI comes with the clone (`deploy/ui-dist`, see above). The install directory is always asked for: pass `--prefix DIR`, or the script prompts for it (and for a confirmation); there is no default. Recommended: `/opt/OpenVPN-Monitoring-Simple`.
|
||||
|
||||
### Alpine (OpenRC)
|
||||
|
||||
```sh
|
||||
apk add git # only to clone; the script installs the rest
|
||||
git clone <repository> /root/ovpmon-src && cd /root/ovpmon-src
|
||||
deploy/native/install.sh --ui-dist /root/ui-dist.tar.gz
|
||||
deploy/native/install.sh --prefix /opt/OpenVPN-Monitoring-Simple
|
||||
```
|
||||
|
||||
### Debian 12
|
||||
@@ -73,7 +118,7 @@ deploy/native/install.sh --ui-dist /root/ui-dist.tar.gz
|
||||
```sh
|
||||
apt-get update && apt-get install -y git
|
||||
git clone <repository> /root/ovpmon-src && cd /root/ovpmon-src
|
||||
deploy/native/install.sh --ui-dist /root/ui-dist.tar.gz
|
||||
deploy/native/install.sh --prefix /opt/OpenVPN-Monitoring-Simple
|
||||
```
|
||||
|
||||
### Ubuntu 24.04
|
||||
@@ -82,15 +127,18 @@ deploy/native/install.sh --ui-dist /root/ui-dist.tar.gz
|
||||
sudo -i
|
||||
apt-get update && apt-get install -y git # make sure the "universe" component is enabled
|
||||
git clone <repository> /root/ovpmon-src && cd /root/ovpmon-src
|
||||
deploy/native/install.sh --ui-dist /root/ui-dist.tar.gz
|
||||
deploy/native/install.sh --prefix /opt/OpenVPN-Monitoring-Simple
|
||||
```
|
||||
|
||||
Options:
|
||||
|
||||
| Option | Meaning |
|
||||
|---|---|
|
||||
| `--prefix DIR` | install directory (default `/opt/OpenVPN-Monitoring-Simple`); letters, digits, `. _ - /` only |
|
||||
| `--ui-dist FILE` | UI archive from `build-ui.sh`; without it a placeholder page is installed |
|
||||
| `--prefix DIR` | install directory, **required**: asked interactively when the option is missing (without a terminal the script stops). Absolute path of letters, digits, `. _ - /`, no trailing `/`; must be new or empty, must not be the repository checkout (or contain it, or lie inside it) and must not be a system directory (`/`, `/opt`, `/root`, `/usr`, `/var`, ...) |
|
||||
| `--ui-dist FILE\|DIR` | UI tarball from `build-ui.sh` or a directory with `index.html`; highest priority |
|
||||
| `--build-ui` | build the UI now from `APP_UI` (Docker, otherwise the host's Node 20.19+) instead of using `deploy/ui-dist` |
|
||||
| `--node-download` | with `--build-ui`: use a temporary official Node 20 (checksum verified, glibc only) |
|
||||
| `--no-ui` | install a placeholder page on purpose; without any UI source and without this option the install stops |
|
||||
| `--https-port N` | HTTPS port of the web UI (default `8088`) |
|
||||
| `--host-name NAME` | DNS name or IP for the certificate and the CORS origin (default: the detected address of the default route) |
|
||||
| `--admin-user NAME` | login of the first administrator (default `admin`) |
|
||||
@@ -115,13 +163,13 @@ The nginx site does not collide with the distribution defaults: the default serv
|
||||
|
||||
| Phase | Content |
|
||||
|---|---|
|
||||
| 0 Preflight | root, OS and version, service manager present, no existing installation (otherwise it points to `update.sh`), source checkout complete, UI archive readable, ports free, free space |
|
||||
| 0 Preflight | root, OS and version, service manager present, no existing installation (otherwise it points to `update.sh`), source checkout complete, UI source found (and built for `--build-ui`; a stale committed build only warns), ports free, free space |
|
||||
| 1 Packages | the table above; GNU tar, Python 3.9+ with `venv` and `sqlite3`, `easy-rsa` checked |
|
||||
| 2 User and directories | user `ovpmon`; `/var/lib/ovpmon` (+ `staging/`), `/var/log/ovpmon`, `/var/log/openvpn` (with `openvpn-status.log` as `root:ovpmon 640`), `/etc/openvpn/scripts`, `/etc/ovpmon` |
|
||||
| 3 Code | `APP_CORE` and `APP_PROFILER` copied to the prefix (without venvs, databases, logs, Dockerfiles), plus the scripts and templates under `deploy/` and `DOCS/General/` (so the install directory can run `update.sh --source ...`); `VERSION` |
|
||||
| 4 Virtualenvs and easy-rsa | two virtualenvs (`pip install -r requirements.txt`, plus `gunicorn` for `APP_CORE`), an import check, the easy-rsa workspace copied from `/usr/share/easy-rsa` into `APP_PROFILER/easy-rsa` (a real directory, never a symlink), code made root-owned and read-only |
|
||||
| 5 Configuration | `/etc/ovpmon/env` (random secret, generated administrator), `/etc/ovpmon/helper.conf`, `/usr/local/sbin/ovpmon-helper`, doas rules and a **self-test** (`ovpmon` runs the helper through doas), forwarding via `/etc/sysctl.d`, OpenVPN prerequisites (Alpine: the `openvpn.conf` link; Debian/Ubuntu: `/etc/openvpn/server/`; the OpenVPN service is **enabled, not started**: there is no `server.conf` yet) |
|
||||
| 6 Services, UI, nginx | the three service definitions installed and enabled, UI files to `/var/www/ovpmon`, a self-signed EC certificate (`/etc/ovpmon/tls/`, SAN: host name, detected IP, `127.0.0.1`, `localhost`), the nginx site, nginx enabled and reloaded |
|
||||
| 6 Services, UI, nginx | the three service definitions installed and enabled, UI files to `/var/www/ovpmon` (validated, swapped in atomically, with `.ui-source-hash`), a self-signed EC certificate (`/etc/ovpmon/tls/`, SAN: host name, detected IP, `127.0.0.1`, `localhost`), the nginx site, nginx enabled and reloaded |
|
||||
| 7 Start and checks | services started; health checks (below) |
|
||||
| 8 Administrator | when a user exists in the monitoring database, the seed is removed from `/etc/ovpmon/env` and `ovpmon-api` is restarted; if the database cannot be read or is empty the seed stays and a warning says so |
|
||||
|
||||
@@ -237,7 +285,8 @@ Persistence:
|
||||
|
||||
```sh
|
||||
deploy/native/update.sh # run from the checkout with the new version
|
||||
deploy/native/update.sh --ui-dist /root/ui-dist.tar.gz # also replace the UI files
|
||||
deploy/native/update.sh --ui-dist /root/ui-dist.tar.gz # install this UI (tarball or directory), always
|
||||
deploy/native/update.sh --build-ui # build the UI from APP_UI on this host and install it
|
||||
deploy/native/update.sh --source /root/ovpmon-src --yes # another checkout, no questions
|
||||
deploy/native/update.sh --no-pull # sources already in place / offline
|
||||
deploy/native/update.sh --rollback # manual rollback to the newest backup
|
||||
@@ -249,13 +298,13 @@ Each phase is logged separately:
|
||||
|
||||
| Phase | What happens | If it fails |
|
||||
|---|---|---|
|
||||
| 0 Preflight | installation present, no unfinished install, source checkout complete, UI archive readable, services state, databases found, free space (backup and new code) | nothing was changed |
|
||||
| 0 Preflight | installation present, no unfinished install, source checkout complete, an explicit UI source readable (`--build-ui`: builder usable), services state, databases found, free space (backup and new code) | nothing was changed |
|
||||
| 1 **Backup** | verified backup in `/var/backups/ovpmon/<UTC timestamp>/` (see below) | the update is **refused**, nothing was changed |
|
||||
| 2 Sources | `git pull --ff-only` of the source checkout (skipped with `--no-pull` or without git) | nothing was changed |
|
||||
| 3 Prepare | new code copied to `<prefix>.new`, fresh virtualenvs with `pip install -r requirements.txt`, import check; new UI extracted next to the web root. **The running system is not touched** | nothing was changed |
|
||||
| 3 Prepare | new code copied to `<prefix>.new`, fresh virtualenvs with `pip install -r requirements.txt`, import check; the UI source is decided (after `git pull`: `--ui-dist`, `--build-ui`, the committed build; unchanged hash means no swap) and the new UI is staged next to the web root. **The running system is not touched** | nothing was changed |
|
||||
| 4 Stop and swap | the three application services are stopped (**OpenVPN keeps running**, VPN users stay connected); a final consistent snapshot; each code directory is renamed to `<dir>.old-<time>`, the new one moved in; **PKI, client profiles, `profiler.log`, `config.ini` and any database files below the code directory are moved over, never replaced**; virtualenv paths fixed | automatic rollback |
|
||||
| 5 **Database migration** | its own step, see below | automatic rollback, **nothing is started** |
|
||||
| 6 Files | UI swap; helper; `helper.conf` (when missing); doas rules; service definitions; missing environment keys added (existing values never changed); nginx site; each replaced only when it differs and is managed by these scripts; units reloaded | automatic rollback |
|
||||
| 6 Files | UI swap (when a new UI was staged); helper; `helper.conf` (when missing); doas rules; service definitions; missing environment keys added (existing values never changed); nginx site; each replaced only when it differs and is managed by these scripts; units reloaded | automatic rollback |
|
||||
| 7 Start | services started, health checks, helper self-test | automatic rollback |
|
||||
| 8 Finish | the old code directories are removed (never one that still holds PKI data), the newest 5 backups kept, state recorded | |
|
||||
|
||||
@@ -348,7 +397,7 @@ A host that was set up by hand (the layout of the old guide: code in `/opt/OpenV
|
||||
| `config.ini` of both components | Kept; the shipped one of the new version is saved as `config.ini.dist` when it differs |
|
||||
| `profiler.log`, other `*.log` / `*.db` files below the code directories | Kept (moved) |
|
||||
| Code, virtualenvs | **Replaced** (fresh virtualenvs; the old ones are in the backup) |
|
||||
| UI files | Replaced only with `--ui-dist`; the previous ones are in the backup |
|
||||
| UI files | Replaced with `--ui-dist` / `--build-ui`, or automatically when the committed build of the source differs from the installed one (`.ui-source-hash`); kept when there is no UI source; the previous ones are in the backup |
|
||||
| Service definitions, nginx site, doas rules, helper | Replaced when they differ and are managed by these scripts; the previous ones are in the backup |
|
||||
| User sessions | Stay valid while the secret is unchanged |
|
||||
| Backups in `/var/backups/ovpmon` | The newest 5 kept, older ones pruned after a successful update; `-pre-restore` copies are never pruned automatically |
|
||||
@@ -358,6 +407,7 @@ A host that was set up by hand (the layout of the old guide: code in `/opt/OpenV
|
||||
|
||||
| Symptom | Cause and action |
|
||||
|---|---|
|
||||
| `invalid --prefix ...` / `no valid install directory given` | The install directory must be a new or empty dedicated directory, not the repository checkout and not a system directory. Move or clone the repository elsewhere (for example `/root/ovpmon-src`) or choose another directory |
|
||||
| `already installed ... use update.sh` / `an installation already exists` | `install.sh` never installs over an installation. Use `update.sh` (it adopts hand-made installations) |
|
||||
| `installation stopped in phase ...` | Fix the cause and run `install.sh` again: it resumes and keeps secrets, certificate and data |
|
||||
| `not a tested version ... needs --force` | Untested OS version: `install.sh --force` at your own risk |
|
||||
@@ -372,7 +422,10 @@ A host that was set up by hand (the layout of the old guide: code in `/opt/OpenV
|
||||
| Clients connect but have no internet | Forwarding or NAT is missing: see the firewall section |
|
||||
| nginx: `conflicting server name` / port in use | Another site uses the same port; change `--https-port` (or the `listen` line of the site and reload) |
|
||||
| Browser warns about the certificate | It is self-signed; check the fingerprint printed by `install.sh`, or install a real certificate under `/etc/ovpmon/tls/` and reload nginx |
|
||||
| UI shows the placeholder page | Installed without `--ui-dist`: `deploy/native/update.sh --ui-dist FILE` |
|
||||
| `no UI source found` (install stops) | The checkout has no `deploy/ui-dist` (incomplete clone, or the maintainer did not publish it) and no `--ui-dist`. Use `--build-ui` (Docker or Node 20.19+; `--node-download` on Debian/Ubuntu), `--ui-dist FILE\|DIR` from another machine, or `--no-ui` for a placeholder page |
|
||||
| Warning "committed UI build ... is OLDER than the APP_UI sources" | Someone changed `APP_UI` without refreshing the build. Maintainers: `deploy/native/build-ui.sh --publish` and commit `deploy/ui-dist`. On the host: `--build-ui` |
|
||||
| `the installed Node is too old` / `node and npm are not installed` (`--build-ui`, `build-ui.sh --local`) | The message lists the commands for the OS: Alpine `apk add nodejs npm`; Debian/Ubuntu `--node-download` or Node 20+ from nodejs.org |
|
||||
| UI shows the placeholder page | Installed with `--no-ui`: run `deploy/native/update.sh` (installs the UI of the repository), or add `--ui-dist` / `--build-ui` |
|
||||
| `su`/`doas` self-test fails on a minimal container | Containers often lack `/etc/pam.d/doas` or a real init system; the services may still work (check health) |
|
||||
|
||||
## Host hardening (recommended, not done by the scripts)
|
||||
|
||||
Reference in new issue
Block a user