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,49 +1,5 @@
|
||||
# OpenRC Service Installation Guide
|
||||
# OpenRC service scripts
|
||||
|
||||
This guide explains how to install and enable the `ovpmon-api` and `ovpmon-gatherer` services on an Alpine Linux (or other OpenRC-based) system.
|
||||
`ovpmon-api`, `ovpmon-gatherer` and `ovpmon-profiler` are the OpenRC scripts (Alpine) of the system-services deployment. They run the services as the user `ovpmon`, source `/etc/ovpmon/env` in `start_pre` and are supervised by `supervise-daemon`.
|
||||
|
||||
## Prerequisites
|
||||
|
||||
- **Paths**: The scripts assume the application is installed at `/opt/ovpmon`.
|
||||
- **Virtualenv**: A python virtual environment should exist at `/opt/ovpmon/venv`.
|
||||
|
||||
If your paths differ, you can edit the scripts directly or create configuration files in `/etc/conf.d/`.
|
||||
|
||||
## Installation Steps
|
||||
|
||||
1. **Copy the scripts to `/etc/init.d/`**:
|
||||
```sh
|
||||
cp ovpmon-api /etc/init.d/
|
||||
cp ovpmon-gatherer /etc/init.d/
|
||||
```
|
||||
|
||||
2. **Make them executable**:
|
||||
```sh
|
||||
chmod 755 /etc/init.d/ovpmon-api
|
||||
chmod 755 /etc/init.d/ovpmon-gatherer
|
||||
```
|
||||
|
||||
3. **Add to default runlevel** (to start on boot):
|
||||
```sh
|
||||
rc-update add ovpmon-api default
|
||||
rc-update add ovpmon-gatherer default
|
||||
```
|
||||
|
||||
4. **Start the services**:
|
||||
```sh
|
||||
rc-service ovpmon-api start
|
||||
rc-service ovpmon-gatherer start
|
||||
```
|
||||
|
||||
## Configuration (Optional)
|
||||
|
||||
You can override default variables without editing the script by creating files in `/etc/conf.d/`.
|
||||
|
||||
**Example `/etc/conf.d/ovpmon-api`**:
|
||||
```sh
|
||||
# Override installation directory
|
||||
directory="/var/www/ovpmon/APP"
|
||||
|
||||
# Override command arguments
|
||||
command_args="/var/www/ovpmon/APP/openvpn_api_v3.py --debug"
|
||||
```
|
||||
Do not copy them by hand: `deploy/native/install.sh` installs them (adjusting the install directory when it is not `/opt/OpenVPN-Monitoring-Simple`) and `deploy/native/update.sh` keeps them current. The full procedure, the layout and the systemd counterparts are in [Scenario 2: system services](../../Deployment/Scenario2_System_Services.md).
|
||||
Regular → Executable
+32
-5
@@ -1,16 +1,43 @@
|
||||
#!/sbin/openrc-run
|
||||
# managed by ovpmon deploy/native (install.sh / update.sh replace this file only while this marker line is present)
|
||||
#
|
||||
# OpenVPN Monitor API (Flask under gunicorn, APP_CORE), OpenRC (Alpine).
|
||||
# Install: deploy/native/install.sh renders this template (install dir, if not the default) into
|
||||
# /etc/init.d/ovpmon-api. Manual use: copy it there (chmod 755), `rc-update add ovpmon-api default`,
|
||||
# `rc-service ovpmon-api start`. Guide: DOCS/Deployment/Scenario2_System_Services.md
|
||||
#
|
||||
# Settings come from /etc/ovpmon/env (root:root 600), sourced in start_pre while still root; the
|
||||
# daemon then runs as ovpmon. supervise-daemon restarts it after a crash.
|
||||
# The service does not depend on openvpn: the VPN server is started from the UI through the root helper.
|
||||
|
||||
name="ovpmon-api"
|
||||
description="OpenVPN Monitor API Service"
|
||||
description="OpenVPN Monitor API (gunicorn)"
|
||||
|
||||
supervisor="supervise-daemon"
|
||||
respawn_delay=3
|
||||
respawn_max=0
|
||||
|
||||
: ${directory:="/opt/ovpmon/APP"}
|
||||
: ${command_user:="root"}
|
||||
command_user="ovpmon:ovpmon"
|
||||
directory="/opt/OpenVPN-Monitoring-Simple/APP_CORE"
|
||||
command="/opt/OpenVPN-Monitoring-Simple/APP_CORE/venv/bin/python"
|
||||
command_args="-m gunicorn -w 2 -b 127.0.0.1:5001 openvpn_api_v3:app"
|
||||
|
||||
command="/opt/ovpmon/venv/bin/python"
|
||||
command_args="/opt/ovpmon/APP/openvpn_api_v3.py"
|
||||
output_log="/var/log/ovpmon/ovpmon-api.log"
|
||||
error_log="/var/log/ovpmon/ovpmon-api.log"
|
||||
|
||||
depend() {
|
||||
need net
|
||||
after firewall
|
||||
}
|
||||
|
||||
start_pre() {
|
||||
# log file writable for the service user (the log directory is owned by ovpmon)
|
||||
checkpath -f -m 0640 -o ovpmon:ovpmon "$output_log" || return 1
|
||||
# export the service environment; the file is data written by install.sh (KEY=VALUE lines)
|
||||
[ -r /etc/ovpmon/env ] || { eerror "/etc/ovpmon/env is missing"; return 1; }
|
||||
set -a
|
||||
. /etc/ovpmon/env
|
||||
set +a
|
||||
# extend, never replace: OpenRC itself needs /lib/rc/bin (ebegin, eend) on the PATH
|
||||
export PATH="/usr/local/sbin:/usr/local/bin:$PATH"
|
||||
}
|
||||
Regular → Executable
+25
-5
@@ -1,16 +1,36 @@
|
||||
#!/sbin/openrc-run
|
||||
# managed by ovpmon deploy/native (install.sh / update.sh replace this file only while this marker line is present)
|
||||
#
|
||||
# OpenVPN Monitor gatherer (reads the OpenVPN status log into the monitoring database, APP_CORE),
|
||||
# OpenRC (Alpine). Install: see ovpmon-api. Settings come from /etc/ovpmon/env.
|
||||
# The gatherer keeps running while OpenVPN is down (it waits for the status log).
|
||||
|
||||
name="ovpmon-gatherer"
|
||||
description="OpenVPN Monitor Gatherer Service"
|
||||
description="OpenVPN Monitor Gatherer"
|
||||
|
||||
supervisor="supervise-daemon"
|
||||
respawn_delay=3
|
||||
respawn_max=0
|
||||
|
||||
: ${directory:="/opt/ovpmon/APP"}
|
||||
: ${command_user:="root"}
|
||||
command_user="ovpmon:ovpmon"
|
||||
directory="/opt/OpenVPN-Monitoring-Simple/APP_CORE"
|
||||
command="/opt/OpenVPN-Monitoring-Simple/APP_CORE/venv/bin/python"
|
||||
command_args="openvpn_gatherer_v3.py"
|
||||
|
||||
command="/opt/ovpmon/venv/bin/python"
|
||||
command_args="/opt/ovpmon/APP/openvpn_gatherer_v3.py"
|
||||
output_log="/var/log/ovpmon/ovpmon-gatherer.log"
|
||||
error_log="/var/log/ovpmon/ovpmon-gatherer.log"
|
||||
|
||||
depend() {
|
||||
need net
|
||||
after firewall
|
||||
}
|
||||
|
||||
start_pre() {
|
||||
checkpath -f -m 0640 -o ovpmon:ovpmon "$output_log" || return 1
|
||||
[ -r /etc/ovpmon/env ] || { eerror "/etc/ovpmon/env is missing"; return 1; }
|
||||
set -a
|
||||
. /etc/ovpmon/env
|
||||
set +a
|
||||
# extend, never replace: OpenRC itself needs /lib/rc/bin (ebegin, eend) on the PATH
|
||||
export PATH="/usr/local/sbin:/usr/local/bin:$PATH"
|
||||
}
|
||||
Regular → Executable
+29
-5
@@ -1,16 +1,40 @@
|
||||
#!/sbin/openrc-run
|
||||
# managed by ovpmon deploy/native (install.sh / update.sh replace this file only while this marker line is present)
|
||||
#
|
||||
# OpenVPN Profiler API (FastAPI under uvicorn, APP_PROFILER), OpenRC (Alpine): PKI (easy-rsa),
|
||||
# profiles, server settings. Install: see ovpmon-api. Settings come from /etc/ovpmon/env.
|
||||
#
|
||||
# Runs as ovpmon. Anything that needs root (install server.conf, publish the CRL, start/stop OpenVPN)
|
||||
# goes through `doas /usr/local/sbin/ovpmon-helper <fixed args>` (rules: /etc/doas.conf or
|
||||
# /etc/doas.d/ovpmon.conf, configuration: /etc/ovpmon/helper.conf).
|
||||
# Started without --reload and without depending on openvpn.
|
||||
|
||||
name="ovpmon-profiler"
|
||||
description="OpenVPN Monitor Profiler Service (FastAPI)"
|
||||
description="OpenVPN Profiler API (uvicorn)"
|
||||
|
||||
supervisor="supervise-daemon"
|
||||
respawn_delay=3
|
||||
respawn_max=0
|
||||
|
||||
: ${directory:="/opt/ovpmon/NEW_MODULES"}
|
||||
: ${command_user:="root"}
|
||||
command_user="ovpmon:ovpmon"
|
||||
directory="/opt/OpenVPN-Monitoring-Simple/APP_PROFILER"
|
||||
command="/opt/OpenVPN-Monitoring-Simple/APP_PROFILER/venv/bin/python"
|
||||
command_args="-m uvicorn main:app --host 127.0.0.1 --port 8000"
|
||||
|
||||
command="/opt/ovpmon/venv/bin/python"
|
||||
command_args="/opt/ovpmon/NEW_MODULES/main.py"
|
||||
output_log="/var/log/ovpmon/ovpmon-profiler.log"
|
||||
error_log="/var/log/ovpmon/ovpmon-profiler.log"
|
||||
|
||||
depend() {
|
||||
need net
|
||||
after firewall
|
||||
}
|
||||
|
||||
start_pre() {
|
||||
checkpath -f -m 0640 -o ovpmon:ovpmon "$output_log" || return 1
|
||||
[ -r /etc/ovpmon/env ] || { eerror "/etc/ovpmon/env is missing"; return 1; }
|
||||
set -a
|
||||
. /etc/ovpmon/env
|
||||
set +a
|
||||
# extend, never replace: OpenRC itself needs /lib/rc/bin (ebegin, eend) on the PATH
|
||||
export PATH="/usr/local/sbin:/usr/local/bin:$PATH"
|
||||
}
|
||||
Reference in new issue
Block a user