Encrypted packages (databases, PKI, client profiles) with safe restore and a pre-restore safety copy, usable for server-to-server migration across container and system-service installs. New Management page, ovp_backups volume, migrations code in the profiler image, server name in package names. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
55 lines
1.7 KiB
Python
55 lines
1.7 KiB
Python
from fastapi import APIRouter, HTTPException
|
|
from pydantic import BaseModel
|
|
from services import process, pki
|
|
from database import get_db
|
|
from sqlalchemy.orm import Session
|
|
from utils.auth import verify_token
|
|
from utils.guards import forbid_during_restore
|
|
from typing import Optional
|
|
from fastapi import Depends
|
|
|
|
router = APIRouter(dependencies=[Depends(verify_token)])
|
|
|
|
class ProcessActionResponse(BaseModel):
|
|
status: str
|
|
message: str
|
|
stdout: Optional[str] = None
|
|
stderr: Optional[str] = None
|
|
|
|
class ProcessStats(BaseModel):
|
|
status: str
|
|
pid: Optional[int] = None
|
|
cpu_percent: float
|
|
memory_mb: float
|
|
uptime: Optional[str] = None
|
|
|
|
@router.post("/server/process/{action}", response_model=ProcessActionResponse, dependencies=[Depends(forbid_during_restore)])
|
|
def manage_process(action: str, db: Session = Depends(get_db)):
|
|
"""
|
|
Control the OpenVPN server process.
|
|
Action: start, stop, restart
|
|
"""
|
|
if action not in ["start", "stop", "restart"]:
|
|
raise HTTPException(status_code=400, detail="Invalid action. Use start, stop, or restart")
|
|
|
|
# Stop stays allowed: it must work after Clear PKI or with a broken setup
|
|
if action in ("start", "restart"):
|
|
try:
|
|
pki.require_server_ready(db)
|
|
except pki.PkiNotReady as e:
|
|
raise HTTPException(status_code=409, detail=str(e))
|
|
|
|
result = process.control_service(action)
|
|
|
|
if result["status"] == "error":
|
|
raise HTTPException(status_code=500, detail=result["message"])
|
|
|
|
return result
|
|
|
|
@router.get("/server/process/stats", response_model=ProcessStats)
|
|
def get_process_stats():
|
|
"""
|
|
Get current telemetry for the OpenVPN process.
|
|
"""
|
|
return process.get_process_stats()
|