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
@@ -9,7 +9,14 @@ logger = logging.getLogger(__name__)
|
||||
def is_container():
|
||||
"""
|
||||
Checks if the application is running inside a Docker container.
|
||||
OVPMON_RUNTIME=host|container overrides the detection (a service that runs on a host inside a
|
||||
test container with /.dockerenv sets host).
|
||||
"""
|
||||
forced = os.environ.get("OVPMON_RUNTIME", "").strip().lower()
|
||||
if forced == "host":
|
||||
return False
|
||||
if forced == "container":
|
||||
return True
|
||||
if os.path.exists('/.dockerenv'):
|
||||
return True
|
||||
try:
|
||||
@@ -23,6 +30,18 @@ def is_container():
|
||||
HELPER_PATH = "/usr/local/sbin/ovpmon-helper"
|
||||
|
||||
|
||||
def openvpn_config_path():
|
||||
"""OpenVPN config path for root/container mode (OVPMON_OPENVPN_CONFIG, default /etc/openvpn/server.conf).
|
||||
Unprivileged mode only stages the file; the helper's own configuration decides where it is installed."""
|
||||
return os.environ.get("OVPMON_OPENVPN_CONFIG", "").strip() or "/etc/openvpn/server.conf"
|
||||
|
||||
|
||||
def openvpn_service_name():
|
||||
"""Service name for the native root path (OVPMON_OPENVPN_SERVICE, default 'openvpn';
|
||||
systemd hosts use 'openvpn-server@server')."""
|
||||
return os.environ.get("OVPMON_OPENVPN_SERVICE", "").strip() or "openvpn"
|
||||
|
||||
|
||||
def _run_helper(args):
|
||||
"""Call the root-side helper through doas (used when this process is unprivileged).
|
||||
Returns (returncode, parsed_json_or_None, raw_output)."""
|
||||
@@ -68,7 +87,7 @@ def control_service(action: str):
|
||||
if action not in ["start", "stop", "restart"]:
|
||||
raise ValueError("Invalid action")
|
||||
|
||||
CONFIG_PATH = "/etc/openvpn/server.conf"
|
||||
CONFIG_PATH = openvpn_config_path()
|
||||
PID_FILE = "/run/openvpn.pid"
|
||||
|
||||
# In Container: Use direct execution to avoid OpenRC/cgroups issues
|
||||
@@ -149,9 +168,9 @@ def control_service(action: str):
|
||||
|
||||
cmd = []
|
||||
if os_type == "alpine":
|
||||
cmd = ["rc-service", "openvpn", action]
|
||||
cmd = ["rc-service", openvpn_service_name(), action]
|
||||
else:
|
||||
cmd = ["systemctl", action, "openvpn"]
|
||||
cmd = ["systemctl", action, openvpn_service_name()]
|
||||
|
||||
try:
|
||||
result = subprocess.run(cmd, capture_output=True, text=True, check=True)
|
||||
|
||||
Reference in new issue
Block a user