# 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. 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 (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 | | `deploy/native/lib.sh` | shared functions and the OS adapter (sourced, not executed) | All scripts run as root, support `-h`, log in one style (UTC time stamp, `=== PHASE n ===`) and append every log line to `/var/log/ovpmon-deploy.log`. ## What is installed ``` Browser --https:8088--> nginx --/--------------> /var/www/ovpmon (UI files) --/api/----------> 127.0.0.1:5001 ovpmon-api (gunicorn, APP_CORE) --/profiles-api/-> 127.0.0.1:8000 ovpmon-profiler (uvicorn, APP_PROFILER) ovpmon-gatherer (APP_CORE): OpenVPN status log -> monitoring database ovpmon-profiler (user ovpmon) --doas--> /usr/local/sbin/ovpmon-helper (root) --> server.conf, CRL, OpenVPN service ``` The three `ovpmon-*` services run as the unprivileged user `ovpmon`. Only the helper acts as root, through six fixed `doas` rules, and it validates everything it installs (see [Privilege separation](../Changes/2026-09-30_Privilege_Separation.md)). The services do not require OpenVPN to be running: the VPN server is created and started from the UI. ## Supported systems | System | Tested version | Service manager | Notes | |---|---|---|---| | Alpine | 3.23 | OpenRC | the original reference platform | | Debian | 12 | systemd | | | Ubuntu | 24.04 LTS | systemd | needs the `universe` repository (`easy-rsa`, `opendoas`) | Another version of these systems is refused with a warning unless you pass `--force` to `install.sh` (the update only warns). Other distributions are not supported (a Debian derivative works with `--force` at your own risk). ## Requirements - A host with root access, a working package manager and Internet access (packages, Python packages from PyPI). - `/dev/net/tun` for OpenVPN (a normal VM has it; in containers it must be passed in). - 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`). - 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). ## The web UI 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 ``` `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). ### 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-.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 (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 /root/ovpmon-src && cd /root/ovpmon-src deploy/native/install.sh --prefix /opt/OpenVPN-Monitoring-Simple ``` ### Debian 12 ```sh apt-get update && apt-get install -y git git clone /root/ovpmon-src && cd /root/ovpmon-src deploy/native/install.sh --prefix /opt/OpenVPN-Monitoring-Simple ``` ### Ubuntu 24.04 ```sh sudo -i apt-get update && apt-get install -y git # make sure the "universe" component is enabled git clone /root/ovpmon-src && cd /root/ovpmon-src deploy/native/install.sh --prefix /opt/OpenVPN-Monitoring-Simple ``` Options: | Option | Meaning | |---|---| | `--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`) | | `--force` | continue on an untested OS version | ### Differences between the systems | | Alpine 3.23 | Debian 12 / Ubuntu 24.04 | |---|---|---| | Packages | `python3 py3-pip nginx openvpn easy-rsa iptables bash doas openssl curl tar` | `python3 python3-venv python3-pip nginx openvpn easy-rsa iptables opendoas openssl curl ca-certificates tar iproute2` | | Service manager | OpenRC: `rc-service NAME start\|stop\|restart\|status`, `rc-update add NAME default` | systemd: `systemctl start\|stop\|restart\|status NAME`, `systemctl enable NAME` | | Our service files | `/etc/init.d/ovpmon-api`, `-gatherer`, `-profiler` (`supervise-daemon`, `command_user=ovpmon:ovpmon`) | `/etc/systemd/system/ovpmon-*.service` (`User=ovpmon`, `EnvironmentFile=/etc/ovpmon/env`) | | Service logs | `/var/log/ovpmon/ovpmon-.log` | `journalctl -u ovpmon-` | | OpenVPN service | `openvpn`; config `/etc/openvpn/server.conf`, plus the link `/etc/openvpn/openvpn.conf -> server.conf` | `openvpn-server@server`; config `/etc/openvpn/server/server.conf` | | nginx site | `/etc/nginx/http.d/ovpmon.conf` | `/etc/nginx/conf.d/ovpmon.conf` | | doas | package `doas`; our rules in `/etc/doas.d/ovpmon.conf` (own file, as on the existing hosts) | package `opendoas`; our rules as a marked block inside `/etc/doas.conf` | | `ovpmon` user | `adduser -S`, shell `/sbin/nologin` | `useradd --system`, shell `/usr/sbin/nologin` | The nginx site does not collide with the distribution defaults: the default server of Alpine and Debian listens on port 80, ours on 8088, and both distribution `nginx.conf` files include the directory above (the installer checks the `include` line). ### What `install.sh` does | Phase | Content | |---|---| | 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` (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 | Health checks: the three services are running; `http://127.0.0.1:5001/` answers; `http://127.0.0.1:8000/` returns 200; `https://127.0.0.1:/` (with `-k`) returns 200; `/api/v1/user/me` and `/profiles-api/config` through nginx return 401 without a token. The final summary shows the URL, the certificate fingerprint, the paths and the **generated administrator password once**. The state is recorded in `/etc/ovpmon/deploy.state` (prefix, HTTPS port, OS, version, dates). If the script fails it is **safe to run again**: it resumes, keeps the existing secret, certificate, easy-rsa workspace and data. Then in the UI: sign in, change the password and enable 2FA, **PKI Configuration -> Initialize PKI**, generate the server configuration, start the VPN server. ### Without the script (outline) Create the `ovpmon` user and the directories, copy the code, build both virtualenvs, write `/etc/ovpmon/env`, `helper.conf` and the doas rules from the templates, install the service definitions (`DOCS/General/systemd/*.service` or `DOCS/General/openrc/ovpmon-*`; replace `/opt/OpenVPN-Monitoring-Simple` if you use another prefix), copy the UI, add the nginx site from `deploy/native/nginx/ovpmon.conf.template` (replace `@HTTPS_PORT@`, `@WEB_ROOT@`, `@TLS_CRT@`, `@TLS_KEY@`). The commands are exactly what `install.sh` runs; reading the script is the shortest reference. ## Layout: what is where, who owns it | Item | Path | Owner, mode | |---|---|---| | Code | `/APP_CORE`, `/APP_PROFILER` | `root:root`, read-only for others | | Virtualenvs | `/APP_CORE/venv`, `/APP_PROFILER/venv` | `root:root` | | **PKI** (CA, keys, certificates, CRL) | `/APP_PROFILER/easy-rsa` (real directory) | `ovpmon:ovpmon` 750 | | **Client profiles** | `/APP_PROFILER/client-config` (real directory) | `ovpmon:ovpmon` 750 | | Profiler log | `/APP_PROFILER/profiler.log` | `ovpmon:ovpmon` 640 | | Shipped settings file | `/APP_CORE/config.ini`, `/APP_PROFILER/config.ini` | `root:root`; the environment file overrides it | | **Databases** | `/var/lib/ovpmon/openvpn_monitor.db`, `ovpn_profiler.db`, migration copies `*.db.bak-*` | `ovpmon:ovpmon` | | Staging of `server.conf` | `/var/lib/ovpmon/staging/` | `ovpmon:ovpmon` 750 | | Service environment | `/etc/ovpmon/env` | `root:root` 600 | | Helper configuration | `/etc/ovpmon/helper.conf` | `root:root` 644 | | TLS certificate and key | `/etc/ovpmon/tls/ovpmon.crt`, `ovpmon.key` | `root:root` (key 600) | | Deployment state | `/etc/ovpmon/deploy.state` | `root:root` 644 | | nftables ruleset of the VPN clients (only after `firewall.sh`) | `/etc/ovpmon/nftables.nft`, service `ovpmon-nft` | `root:root` 644 | | Root helper | `/usr/local/sbin/ovpmon-helper` | `root:root` 755 | | doas rules | Alpine: `/etc/doas.d/ovpmon.conf`; Debian/Ubuntu: block in `/etc/doas.conf` | `root:root` | | OpenVPN configuration | `/etc/openvpn/server.conf` (Alpine) or `/etc/openvpn/server/server.conf`, `/etc/openvpn/crl.pem`, `/etc/openvpn/scripts/` | `root:root` | | OpenVPN logs | `/var/log/openvpn/openvpn.log`, `openvpn-status.log` (`root:ovpmon` 640) | `root` | | Service logs | `/var/log/ovpmon/` (OpenRC) or the journal (systemd) | `ovpmon` / systemd | | UI files | `/var/www/ovpmon` | `root:root` | | Backups | `/var/backups/ovpmon//` | `root:root` 700 | | Deployment log | `/var/log/ovpmon-deploy.log` | `root:root` 600 | The profiler resolves `easy-rsa/` and `client-config/` relative to its working directory (`APP_PROFILER`) and keeps `client-config/.ovpn` as a relative path in its database; therefore both are real directories inside `APP_PROFILER` (a symlinked `client-config` breaks the real-path checks and the `clear_pki` cleanup). ## Environment file and helper configuration `/etc/ovpmon/env` (`root:root` 600) is read by the init system as root and handed to the services. Lines are `KEY=VALUE` without quotes or spaces (systemd and OpenRC read the same file). | Variable | Default written by `install.sh` | Meaning | |---|---|---| | `OVPMON_API_SECRET_KEY` | random, 64 hex characters | signing key of both APIs; changing it logs everybody out; keep it across updates | | `OVPMON_API_HOST`, `OVPMON_API_PORT` | `127.0.0.1`, `5001` | informational: gunicorn is started with `-b 127.0.0.1:5001` | | `OVPMON_OPENVPN_MONITOR_DB_PATH` | `/var/lib/ovpmon/openvpn_monitor.db` | monitoring database | | `OVPMON_PROFILER_DB_PATH` | `/var/lib/ovpmon/ovpn_profiler.db` | profiler database | | `OVPMON_OPENVPN_MONITOR_LOG_PATH` | `/var/log/openvpn/openvpn-status.log` | status log read by the gatherer | | `OVPMON_LOGGING_LEVEL` | `INFO` | | | `OVPMON_CORS_ORIGINS` | `https://:` | extra allowed origin (the UI is same-origin behind nginx) | | `OVPMON_RUNTIME` | `host` | forces host mode (never "container"), needed when the host itself runs inside a container | | `OVPMON_OPENVPN_SERVICE` | `openvpn` (Alpine) / `openvpn-server@server` | service name for the root (non-helper) path | | `OVPMON_OPENVPN_CONFIG` | `/etc/openvpn/server.conf` / `/etc/openvpn/server/server.conf` | server config path for the root (non-helper) path | | `OVPMON_INITIAL_ADMIN_USER`, `OVPMON_INITIAL_ADMIN_PASSWORD` | generated | seed, only while the users table is empty; removed by `install.sh` after the first start | | `OVPMON_AUTO_MIGRATE` | unset | `0` makes the services refuse to start while migrations are pending | With the unprivileged profiler the API only stages `server.conf`; **the helper configuration decides where it is installed and which service is controlled.** `/etc/ovpmon/helper.conf` (INI, section `[helper]`, `root:root`, not group/world writable, otherwise the helper refuses to run). Without the file the helper uses the built-in values of the Alpine layout. | Key | Alpine (written) | Debian/Ubuntu (written) | Rule | |---|---|---|---| | `install_dir` | `/opt/OpenVPN-Monitoring-Simple` | same | absolute, no `..`; the PKI is `/APP_PROFILER/easy-rsa/pki` | | `service_manager` | `openrc` | `systemd` | `openrc` or `systemd` | | `service_unit` | `openvpn` | `openvpn-server@server` | `^[A-Za-z0-9@._-]{1,64}$`, not starting with `-` or `.` | | `config_path` | `/etc/openvpn/server.conf` | `/etc/openvpn/server/server.conf` | absolute, below `/etc/openvpn/`, ends with `.conf` | | `staged_path` | `/var/lib/ovpmon/staging/server.conf` | same | absolute, below `/var/lib/ovpmon/` | OpenRC runs `/sbin/rc-service `, systemd runs `systemctl ` (fixed argument list, fixed `PATH`). Unknown keys or invalid values make the helper refuse. ## Firewall, NAT and forwarding `install.sh` and `update.sh` **never touch the firewall**. `net.ipv4.ip_forward=1` is set persistently in `/etc/sysctl.d/98-ovpmon-forward.conf`. Opening the ports (UI, VPN) is yours. NAT and packet tuning for the VPN clients are done by a separate opt-in script. ### `deploy/native/firewall.sh` (nftables) Reads the interfaces of this server and applies, for traffic **from the VPN network to every other network**: masquerade, TCP MSS clamping (path MTU tuning) and TTL tuning. Run it as root after the VPN server configuration exists (the VPN network is read from the `server` line of `server.conf`). ```sh deploy/native/firewall.sh --dry-run # show what was detected and the ruleset; change nothing deploy/native/firewall.sh # apply, ask for confirmation, load at boot deploy/native/firewall.sh status # loaded rules with counters, boot service, detected parameters deploy/native/firewall.sh remove # delete the rules, the ruleset file and the boot service ``` | Option | Meaning | |---|---| | `--vpn-net CIDR` | VPN network. Default: `server` line of the OpenVPN config, else the address of the VPN interface | | `--vpn-if NAME` | VPN interface. Default: the interface with an address in the VPN network, else the `dev` line, else `tun*` | | `--out-if A,B` | Only these interfaces (exact names) are "other networks". Default: every interface except `lo` and the VPN interface, so new uplinks (VLAN, `hytun`, a second ISP) need no rerun | | `--ttl N` / `--no-ttl` | TTL of packets leaving towards the other networks (default 64, set after the forwarding decrement) | | `--mss pmtu\|N` / `--no-mss` | TCP MSS of SYN and SYN-ACK in both directions: `pmtu` = MTU of the route of each connection (default), or a fixed value | | `--no-persist` | Running kernel only: no ruleset file, no boot service | | `--yes`, `--force` | No questions; continue on an untested OS version | What it creates: only the table `ip ovpmon` (replaced atomically with `nft -f`; other tables and the distribution's `nftables.service` are not touched), the ruleset file `/etc/ovpmon/nftables.nft` and the boot service `ovpmon-nft` (systemd oneshot / OpenRC). The `nftables` package is installed on request only (it is not part of the install packages). IPv4 only. Notes: - "Every other network" includes container bridges and tunnels on the host; use `--out-if` to limit it. - The VPN network must not overlap with the network of another interface (the script stops). - The options are not remembered: after a change of the VPN subnet in the UI run the script again with the same options. - The MSS clamp complements `tun-mtu` / `mssfix` of the server settings, it does not replace them. If another nftables table has a `policy drop`, allow the VPN traffic and ICMP "fragmentation needed" (type 3, code 4) there, otherwise path MTU discovery fails. - Old manual rules (`iptables -t nat ... MASQUERADE` for the same network) are reported: remove them when this script is the one to keep. - The filtering policy (INPUT/FORWARD allow/drop, ports, anti-leak) is not part of the script. ### Manual rules (iptables / nftables) Replace `eth0` with the uplink interface and `172.20.1.0/24` with the VPN subnet of the server settings. ```sh # iptables: services iptables -A INPUT -p tcp --dport 8088 -j ACCEPT # UI (your HTTPS port) iptables -A INPUT -p udp --dport 1194 -j ACCEPT # OpenVPN (your VPN port) # iptables: NAT and forwarding for the VPN clients iptables -t nat -A POSTROUTING -s 172.20.1.0/24 -o eth0 -j MASQUERADE iptables -A FORWARD -i tun+ -o eth0 -j ACCEPT iptables -A FORWARD -i eth0 -o tun+ -m conntrack --ctstate RELATED,ESTABLISHED -j ACCEPT ``` nftables equivalent: ```sh nft add table inet ovpmon nft 'add chain inet ovpmon input { type filter hook input priority 0 ; }' nft add rule inet ovpmon input tcp dport 8088 accept nft add rule inet ovpmon input udp dport 1194 accept nft 'add chain inet ovpmon forward { type filter hook forward priority 0 ; }' nft add rule inet ovpmon forward iifname "tun*" oifname "eth0" accept nft add rule inet ovpmon forward iifname "eth0" oifname "tun*" ct state established,related accept nft 'add table ip ovpmon_nat' nft 'add chain ip ovpmon_nat postrouting { type nat hook postrouting priority 100 ; }' nft add rule ip ovpmon_nat postrouting ip saddr 172.20.1.0/24 oifname "eth0" masquerade ``` (Add the `input`/`forward` rules only when your firewall policy is `drop`; a chain with priority 0 and policy accept does not block anything on its own.) Persistence: | System | Make the rules survive a reboot | |---|---| | Alpine | `rc-service iptables save && rc-update add iptables` (rules in `/etc/iptables/rules-save`); nftables: `rc-update add nftables`, rules in `/etc/nftables.nft` | | Debian / Ubuntu | `apt-get install iptables-persistent`, then `netfilter-persistent save`; nftables: put the rules in `/etc/nftables.conf` and `systemctl enable nftables` | ## Update ```sh deploy/native/update.sh # run from the checkout with the new version 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 ``` Run it from the checkout that holds the new version (the script uses the templates of that checkout). `--prefix` and the HTTPS port come from `/etc/ovpmon/deploy.state`. The update needs access to PyPI for the new virtualenvs. Each phase is logged separately: | Phase | What happens | If it fails | |---|---|---| | 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//` (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 `.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 `.old-