ADAPT-Chase's picture
Add files using upload-large-folder tool
fbf3c28 verified
"""
id: service
title: Service Ops (unsafe)
author: admin
description: Seed DB, restart Open WebUI, and tail logs.
version: 0.1.0
license: Proprietary
"""
import subprocess
class Tools:
def seed(self) -> dict:
"""Run OUI-MAX bootstrap seeding."""
p = subprocess.run(
["bash", "-lc", "/data/adaptai/projects/oui-max/scripts/bootstrap.sh"],
capture_output=True,
text=True,
)
return {"stdout": p.stdout, "stderr": p.stderr, "exit_code": p.returncode}
def restart_openwebui(self) -> dict:
"""Restart Open WebUI via supervisor script."""
cmd = "pkill -f '/venv/main/bin/open-webui serve' || true; sleep 1; pkill -9 -f '/venv/main/bin/open-webui serve' || true; setsid /opt/supervisor-scripts/open_webui.sh >/dev/null 2>&1 < /dev/null & sleep 2; pgrep -fl 'open-webui serve' || true"
p = subprocess.run(["bash", "-lc", cmd], capture_output=True, text=True)
return {"stdout": p.stdout, "stderr": p.stderr, "exit_code": p.returncode}
def tail_logs(
self, path: str = "/var/log/portal/open_webui.log", lines: int = 200
) -> dict:
"""Tail last N lines of a log file."""
p = subprocess.run(
["bash", "-lc", f"tail -n {lines} {path}"], capture_output=True, text=True
)
return {"stdout": p.stdout, "stderr": p.stderr, "exit_code": p.returncode}