Scenario 2: install and update as system services (Alpine, Debian, Ubuntu)
- deploy/native: install.sh, update.sh (backup, new code prepared aside, stop services, separate DB migration phase, start, automatic rollback; OpenVPN keeps running), backup.sh, restore.sh, build-ui.sh (Node 20 container), lib.sh OS adapter (OpenRC and systemd). - Root helper reads /etc/ovpmon/helper.conf (service manager, unit, config path), validated strictly; process.py/server.py honour OVPMON_RUNTIME, OVPMON_OPENVPN_SERVICE, OVPMON_OPENVPN_CONFIG. Debian/Ubuntu use openvpn-server@server and /etc/openvpn/server/server.conf. - Service definitions rewritten (systemd, OpenRC). Fixes found by real runs: no seccomp-based options in the profiler unit (they imply NoNewPrivileges and break setuid doas); OpenRC start_pre extends PATH instead of replacing it; helper syntax check works on a read-only tree. - Verified in containers with real init systems (Debian 12, Ubuntu 24.04, Alpine 3.23): install, PKI/server config/OpenVPN start, update on pre-versioned databases, rollback, backup/restore. - Test: test_helper_config.py. Docs: Scenario 2 guide, change summary, README, Index. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
1c49d0b9c2
commit
4abd2044f0
26 files changed
+3326
-255
No files matched your search
@@ -1,93 +1,31 @@
|
||||
# Service Setup Guide
|
||||
|
||||
This guide describes how to set up the OpenVPN Monitor components as system services.
|
||||
The OpenVPN Monitor components run as three system services under the unprivileged user `ovpmon`. `deploy/native/install.sh` installs and enables them (see [Scenario 2: system services](../Deployment/Scenario2_System_Services.md)); this page is the day-to-day reference.
|
||||
|
||||
## Components
|
||||
| Service | Command (working directory under the install dir, default `/opt/OpenVPN-Monitoring-Simple`) | Listens |
|
||||
|---|---|---|
|
||||
| `ovpmon-api` | `APP_CORE/venv/bin/python -m gunicorn -w 2 -b 127.0.0.1:5001 openvpn_api_v3:app` | 127.0.0.1:5001 |
|
||||
| `ovpmon-gatherer` | `APP_CORE/venv/bin/python openvpn_gatherer_v3.py` | - |
|
||||
| `ovpmon-profiler` | `APP_PROFILER/venv/bin/python -m uvicorn main:app --host 127.0.0.1 --port 8000` | 127.0.0.1:8000 |
|
||||
|
||||
1. **ovpmon-api**: The main Flask API (`APP/openvpn_api_v3.py`).
|
||||
2. **ovpmon-gatherer**: The background data gatherer (`APP/openvpn_gatherer_v3.py`).
|
||||
3. **ovpmon-profiler**: The new FastAPI profiler module (`NEW_MODULES/main.py`).
|
||||
Settings: `/etc/ovpmon/env` (`root:root` 600). The services start after the network and do not depend on OpenVPN.
|
||||
|
||||
## Common Prerequisites
|
||||
## Definitions
|
||||
|
||||
- **Install Directory**: `/opt/ovpmon` (Recommended)
|
||||
- **Virtual Environment**: `/opt/ovpmon/venv`
|
||||
- Alpine (OpenRC): [`openrc/ovpmon-*`](openrc/INSTALL.md) in `/etc/init.d/` (`supervise-daemon`, `command_user=ovpmon:ovpmon`, environment sourced in `start_pre`, log in `/var/log/ovpmon/`).
|
||||
- Debian / Ubuntu (systemd): [`systemd/ovpmon-*.service`](systemd) in `/etc/systemd/system/` (`User=ovpmon`, `EnvironmentFile=/etc/ovpmon/env`, moderate hardening, log in the journal).
|
||||
|
||||
---
|
||||
Install them with the scripts (they adjust the install directory); by hand, copy a file, replace `/opt/OpenVPN-Monitoring-Simple` if needed and enable it as below.
|
||||
|
||||
## 1. Alpine Linux (OpenRC)
|
||||
## Commands
|
||||
|
||||
### Installation
|
||||
| | OpenRC (Alpine) | systemd (Debian, Ubuntu) |
|
||||
|---|---|---|
|
||||
| Enable at boot | `rc-update add ovpmon-api default` | `systemctl enable ovpmon-api` |
|
||||
| Start / stop / restart | `rc-service ovpmon-api start\|stop\|restart` | `systemctl start\|stop\|restart ovpmon-api` |
|
||||
| Status | `rc-service ovpmon-api status` | `systemctl status ovpmon-api` |
|
||||
| Log | `tail -f /var/log/ovpmon/ovpmon-api.log` | `journalctl -u ovpmon-api -f` |
|
||||
| After editing `/etc/ovpmon/env` | restart the services | restart the services |
|
||||
| After editing a unit file | - | `systemctl daemon-reload` |
|
||||
|
||||
1. **Copy Service Scripts**:
|
||||
Copy the scripts from `Deployment/APP/openrc/` to `/etc/init.d/`.
|
||||
|
||||
```sh
|
||||
cp DOCS/General/openrc/ovpmon-api /etc/init.d/
|
||||
cp DOCS/General/openrc/ovpmon-gatherer /etc/init.d/
|
||||
cp DOCS/General/openrc/ovpmon-profiler /etc/init.d/
|
||||
```
|
||||
|
||||
2. **Set Permissions**:
|
||||
```sh
|
||||
chmod +x /etc/init.d/ovpmon-*
|
||||
```
|
||||
|
||||
3. **Enable Services**:
|
||||
```sh
|
||||
rc-update add ovpmon-api default
|
||||
rc-update add ovpmon-gatherer default
|
||||
rc-update add ovpmon-profiler default
|
||||
```
|
||||
|
||||
4. **Start Services**:
|
||||
```sh
|
||||
rc-service ovpmon-api start
|
||||
rc-service ovpmon-gatherer start
|
||||
rc-service ovpmon-profiler start
|
||||
```
|
||||
|
||||
### Configuration
|
||||
|
||||
To override defaults (e.g., if you installed to a different directory), create files in `/etc/conf.d/`:
|
||||
|
||||
**File:** `/etc/conf.d/ovpmon-api` (example)
|
||||
```sh
|
||||
directory="/var/www/my-monitoring"
|
||||
command_args="/var/www/my-monitoring/APP_CORE/openvpn_api_v3.py"
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## 2. Debian / Ubuntu (Systemd)
|
||||
|
||||
### Installation Steps
|
||||
|
||||
1. **Copy Service Files**:
|
||||
Copy the provided service files from `DOCS/General/systemd/` to `/etc/systemd/system/`.
|
||||
|
||||
```bash
|
||||
cp DOCS/General/systemd/ovpmon-api.service /etc/systemd/system/
|
||||
cp DOCS/General/systemd/ovpmon-gatherer.service /etc/systemd/system/
|
||||
cp DOCS/General/systemd/ovpmon-profiler.service /etc/systemd/system/
|
||||
```
|
||||
|
||||
2. **Reload Daemon**:
|
||||
```bash
|
||||
systemctl daemon-reload
|
||||
```
|
||||
|
||||
3. **Enable Services** (Start on boot):
|
||||
```bash
|
||||
systemctl enable ovpmon-api ovpmon-gatherer ovpmon-profiler
|
||||
```
|
||||
|
||||
4. **Start Services**:
|
||||
```bash
|
||||
systemctl start ovpmon-api ovpmon-gatherer ovpmon-profiler
|
||||
```
|
||||
|
||||
5. **Check Status**:
|
||||
```bash
|
||||
systemctl status ovpmon-api
|
||||
```
|
||||
The OpenVPN server itself (`openvpn` on Alpine, `openvpn-server@server` on Debian/Ubuntu) is started and stopped from the UI through the root helper (`doas`); it is not an `ovpmon-*` service.
|
||||
Reference in new issue
Block a user