Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion aquila/assets/client/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ Environment variables are read from `~/.local/share/aquila/client/.env`:
| --- | --- | --- |
| `MODEL_DIRS` | *(unset)* | Comma-separated directories for local models/LoRA adapters. |
| `MAX_FAILED_RESTARTS` | `3` | Crash-loop breaker per deployment. |
| `HF_CACHE_DIR` | `~/.cache/huggingface` | Shared HuggingFace model cache. |
| `HF_CACHE_DIR` | `~/.local/share/aquila/models` | Shared HuggingFace model cache. In service mode, set to `{runtime_dir}/models`. |
| `VLLM_CLIENT_ROOT` | `~/.vllm-client` | Root for deployment logs, packages, local models, compile caches. In service mode, set to the runtime directory. |
| `LOG_MAX_MB` | `50` | Rotate deployment logs at this size. |
| `LOG_RETENTION_DAYS` | `14` | Delete old log files after this many days. |
| `PODMAN_SOCK` | *(auto)* | Non-standard Podman API socket path. |
Expand Down
7 changes: 5 additions & 2 deletions aquila/assets/client/app/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,10 @@ class Settings(BaseSettings):
vllm_image_repo: str = "vllm/vllm-openai"
# Host directory mounted into every vLLM container as the HuggingFace cache so
# model weights are downloaded once and shared across deployments.
hf_cache_dir: str = "~/.cache/huggingface"
hf_cache_dir: str = "~/.local/share/aquila/models"
# Root directory for deployment logs, uploaded packages, local models, and
# compile caches.
vllm_client_root: str = "~/.vllm-client"

# Default crash-loop breaker threshold: stop a deployment that restarts
# this many times without ever becoming ready. Overridable per deployment.
Expand All @@ -27,7 +30,7 @@ class Settings(BaseSettings):
# same path. Empty = local paths rejected.
model_dirs: str = ""

# Persistent deployment logs (~/.vllm-client/.logs): rotate a deployment's
# Persistent deployment logs ({vllm_client_root}/.logs): rotate a deployment's
# log file once it exceeds this size, and delete files untouched for this
# many days.
log_max_mb: int = 50
Expand Down
2 changes: 1 addition & 1 deletion aquila/assets/client/app/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ def _get_latest_vllm_version() -> str:
# a candidate RAM sleeper when scanning for orphaned warm artifacts.
_SLEEPER_RSS_MIN_MB = 1024

_CLIENT_ROOT = Path(os.environ.get("VLLM_CLIENT_ROOT", Path.home() / ".vllm-client"))
_CLIENT_ROOT = Path(os.path.expanduser(settings.vllm_client_root)).resolve()
_PACKAGES_DIR = _CLIENT_ROOT / ".packages"
# Managed local models (uploaded through the host or pulled from a URL).
# Always part of the allowed model dirs and mounted into vLLM containers.
Expand Down
8 changes: 7 additions & 1 deletion aquila/assets/host/backend/app/api/deployments.py
Original file line number Diff line number Diff line change
Expand Up @@ -623,11 +623,17 @@ async def resume_deployment(
async def delete_deployment(
deployment_id: int, session: AsyncSession = Depends(get_session)
) -> dict[str, str]:
"""Delete the deployment record and remove it from scoped API keys. Does not stop a running container -- call stop first."""
"""Delete the deployment record, stopping its container first if still active."""
deployment = await session.get(Deployment, deployment_id)
if not deployment:
raise HTTPException(status_code=404, detail="Deployment not found")

if deployment.status in ACTIVE_STATUSES:
node = await session.get(Node, deployment.node_id)
await stop_deployment_internal(
deployment, node, best_effort=True, final_status="stopped"
)

await session.delete(deployment)

# Remove this deployment from any scoped API keys.
Expand Down
2 changes: 1 addition & 1 deletion aquila/assets/host/backend/app/services/sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -616,7 +616,7 @@ async def sync_deployments_from_clients(interval_seconds: int = 5) -> None:
if not dep_key or dep_key in known_keys:
continue
client_status = client_dep.get("status")
if client_status in ("stopped", "error"):
if client_status in ("stopped", "error", "expired"):
continue
port = int(client_dep.get("port", 0))
# An active row already holds this port (e.g. a
Expand Down
63 changes: 56 additions & 7 deletions aquila/cli.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import argparse
import getpass
import grp
import hashlib
import pwd

from aquila import __version__
import os
Expand Down Expand Up @@ -613,18 +616,30 @@ def run_client_down() -> None:


def run_clean(remove_docker: bool = False, assume_yes: bool = False) -> None:
"""Remove the tool's runtime directories, venvs, and caches.
"""Remove the tool's runtime directories, venvs, caches, and legacy model caches.

Targets the host/client runtime dirs under XDG data home and the client
working root (uploaded packages). The HuggingFace model cache is left
intact. systemd units are not removed here — use `host down`/`client down`.
Targets the host/client runtime dirs under XDG data home, the client
working root, and legacy HuggingFace cache locations that are no longer
used. systemd units are not removed here — use `host down`/`client down`.
"""
base_dir = Path(os.environ.get("XDG_DATA_HOME", Path.home() / ".local" / "share"))
data_root = base_dir / "aquila"
client_root = Path(os.environ.get("VLLM_CLIENT_ROOT", Path.home() / ".vllm-client"))
legacy_roots = [base_dir / "athanor", base_dir / "vllm_cluster_manager"]
legacy_caches = [
Path.home() / ".cache" / "huggingface",
Path("/root/.cache/huggingface"),
Path("/root/.vllm-client"),
]

targets = [p for p in (data_root, client_root, *legacy_roots) if p.exists()]
cache_targets = []
for p in legacy_caches:
try:
if p.exists():
cache_targets.append(p)
except OSError:
pass

candidate_units = (
f"{HOST_SERVICE_NAME}-infra.service",
Expand All @@ -634,7 +649,7 @@ def run_clean(remove_docker: bool = False, assume_yes: bool = False) -> None:
)
installed_units = [u for u in candidate_units if Path(f"/etc/systemd/system/{u}").exists()]

if not targets and not remove_docker:
if not targets and not cache_targets and not remove_docker:
print("Nothing to clean.")
if installed_units:
print("Installed systemd services remain; remove with `host down` / `client down`.")
Expand All @@ -643,11 +658,12 @@ def run_clean(remove_docker: bool = False, assume_yes: bool = False) -> None:
print("aquila clean will remove:")
for p in targets:
print(f" - {p}")
for p in cache_targets:
print(f" - {p} (legacy model cache)")
if (data_root / "host").exists():
print(" - Docker: Postgres data volume (all deployments, nodes, history)")
if remove_docker:
print(" - Docker: managed vLLM containers and cached vLLM images")
print(" (the HuggingFace model cache is left intact)")
if installed_units:
print("\nNote: systemd services are installed and will NOT be removed:")
for u in installed_units:
Expand Down Expand Up @@ -684,7 +700,7 @@ def run_clean(remove_docker: bool = False, assume_yes: bool = False) -> None:
_clean_docker()

failures: list[Path] = []
for p in targets:
for p in targets + cache_targets:
shutil.rmtree(p, ignore_errors=True)
if p.exists():
failures.append(p)
Expand Down Expand Up @@ -856,12 +872,15 @@ def copy_assets_subdir(kind: str, subdir: str, dest: Path) -> None:


def write_client_env_file(runtime_dir: Path, config: ClientConfig) -> None:
models_dir = runtime_dir / "models"
client_env = textwrap.dedent(
f"""
NODE_NAME={config.node_name}
HOST={config.client_host}
PORT={config.client_port}
CONSUL_HTTP_ADDR=http://{config.host_ip}:{config.consul_port}
HF_CACHE_DIR={models_dir}
VLLM_CLIENT_ROOT={runtime_dir}
"""
).strip() + "\n"
(runtime_dir / ".env").write_text(client_env, encoding="utf-8")
Expand Down Expand Up @@ -963,8 +982,20 @@ def compose_service_cmd(args: str) -> str:
)


def _service_user() -> tuple[str, str]:
"""Return (user, group) for systemd units — the real user behind sudo."""
user = os.environ.get("SUDO_USER") or getpass.getuser()
try:
gid = os.stat(Path(f"~{user}").expanduser()).st_gid
group = grp.getgrgid(gid).gr_name
except (KeyError, OSError):
group = user
return user, group


def install_host_service(config: HostConfig) -> None:
runtime_dir = ensure_runtime_dir("host")
user, group = _service_user()
compose_start = compose_service_cmd("up -d")
compose_stop = compose_service_cmd("down")
npm_path = shutil.which("npm")
Expand All @@ -987,6 +1018,8 @@ def install_host_service(config: HostConfig) -> None:

[Service]
Type=oneshot
User={user}
Group={group}
WorkingDirectory={runtime_dir}
EnvironmentFile={runtime_dir}/.env
ExecStart={compose_start}
Expand All @@ -1007,6 +1040,8 @@ def install_host_service(config: HostConfig) -> None:

[Service]
Type=simple
User={user}
Group={group}
WorkingDirectory={runtime_dir}/backend
EnvironmentFile={runtime_dir}/backend/.env
Environment=AQUILA_VERSION={__version__}
Expand All @@ -1028,6 +1063,8 @@ def install_host_service(config: HostConfig) -> None:

[Service]
Type=simple
User={user}
Group={group}
WorkingDirectory={runtime_dir}/frontend
EnvironmentFile={runtime_dir}/frontend/.env
Environment=PATH={frontend_path}
Expand Down Expand Up @@ -1061,6 +1098,11 @@ def remove_host_service() -> None:

def install_client_service(config: ClientConfig) -> None:
runtime_dir = ensure_runtime_dir("client")
user, group = _service_user()
try:
uid = pwd.getpwnam(user).pw_uid
except KeyError:
uid = os.getuid()
client_service = textwrap.dedent(
f"""
[Unit]
Expand All @@ -1069,6 +1111,9 @@ def install_client_service(config: ClientConfig) -> None:

[Service]
Type=simple
User={user}
Group={group}
Environment=XDG_RUNTIME_DIR=/run/user/{uid}
WorkingDirectory={runtime_dir}
EnvironmentFile={runtime_dir}/.env
Environment=AQUILA_VERSION={__version__}
Expand All @@ -1082,6 +1127,10 @@ def install_client_service(config: ClientConfig) -> None:
).strip() + "\n"

write_systemd_service(f"/etc/systemd/system/{CLIENT_SERVICE_NAME}.service", client_service)
try:
run(["loginctl", "enable-linger", user], capture=True)
except Exception:
pass
systemctl(["daemon-reload"])


Expand Down
4 changes: 2 additions & 2 deletions docs/deployments.md
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ The easiest way to get a local checkpoint onto a node is the node's **Manage** d
- **Upload Archive** — same, but as a single `.tar.gz`/`.zip`; the node extracts it (a single wrapping folder is flattened automatically so `config.json` ends up at the model root).
- **Pull from URL** — paste an `http(s)` URL (e.g. a presigned S3 link) and the node downloads it directly; progress shows in the dialog. Archives are extracted; a single-file URL (e.g. a `.gguf`) is stored as-is.

Uploaded models live under `~/.vllm-client/.models/<name>` on the node, are always part of the allowed model dirs (no `MODEL_DIRS` configuration needed), and are mounted read-only into every new vLLM container. The dialog lists them with size and in-use status; managed models can be deleted there when no deployment serves them. Model names must be a single path segment (letters, digits, `.`, `_`, `-`), and an upload to an existing name is rejected — delete the old model first.
Uploaded models live under `{VLLM_CLIENT_ROOT}/.models/<name>` on the node (default `~/.vllm-client/.models/<name>`; in service mode, under the runtime directory), are always part of the allowed model dirs (no `MODEL_DIRS` configuration needed), and are mounted read-only into every new vLLM container. The dialog lists them with size and in-use status; managed models can be deleted there when no deployment serves them. Model names must be a single path segment (letters, digits, `.`, `_`, `-`), and an upload to an existing name is rejected — delete the old model first.

To deploy one, select the node in the **Deploy Model** form and pick it from the **Local model on this node** dropdown (it fills the model name with the checkpoint's absolute path). Transfers are checked against the node's free disk space up front, and interrupted uploads are cleaned up automatically.

Expand Down Expand Up @@ -221,7 +221,7 @@ Click **Logs** on any deployment to stream its output in real time. Every line i

Monitoring noise is filtered out: the HTTP access-log lines produced by the agent's own `/metrics` polling and `/health` checks (every ~15 s) never enter the log. Inference request lines (`POST /v1/...`) and the engine's throughput stats are kept.

The dialog shows the live tail (last ~400 lines). The **full log of the current run** is persisted on the node under `~/.vllm-client/.logs/` and survives agent restarts without gaps or duplicates — use **Download full log** in the logs dialog to fetch it. One file per deployment run is kept (the previous run remains as `<file>.1`); files rotate at `LOG_MAX_MB` (default 50 MB) and are deleted after `LOG_RETENTION_DAYS` (default 14) without activity — see [Operations](operations.md#configuration).
The dialog shows the live tail (last ~400 lines). The **full log of the current run** is persisted on the node under `{VLLM_CLIENT_ROOT}/.logs/` (default `~/.vllm-client/.logs/`; in service mode, under the runtime directory) and survives agent restarts without gaps or duplicates — use **Download full log** in the logs dialog to fetch it. One file per deployment run is kept (the previous run remains as `<file>.1`); files rotate at `LOG_MAX_MB` (default 50 MB) and are deleted after `LOG_RETENTION_DAYS` (default 14) without activity — see [Operations](operations.md#configuration).

## Connecting to a deployment

Expand Down
5 changes: 3 additions & 2 deletions docs/operations.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,9 @@ These act as defaults for the corresponding [dashboard settings](#global-setting
| --- | --- | --- |
| `MODEL_DIRS` | *(unset)* | Comma-separated directories that may be served as local models / LoRA adapters (mounted read-only into containers). Unset = local paths rejected. |
| `MAX_FAILED_RESTARTS` | `3` | Crash-loop breaker: stop a deployment that restarts this many times without becoming ready. Overridable per deployment. |
| `HF_CACHE_DIR` | `~/.cache/huggingface` | Host directory used as the shared HuggingFace cache. |
| `LOG_MAX_MB` | `50` | Rotate a deployment's persistent log file (`~/.vllm-client/.logs`) once it exceeds this size; the overflow is kept as `<file>.1`. |
| `HF_CACHE_DIR` | `~/.local/share/aquila/models` | Host directory used as the shared HuggingFace cache. In service mode, automatically set to `{runtime_dir}/models`. |
| `VLLM_CLIENT_ROOT` | `~/.vllm-client` | Root directory for deployment logs, uploaded packages, local models, and compile caches. In service mode, automatically set to the runtime directory. |
| `LOG_MAX_MB` | `50` | Rotate a deployment's persistent log file (`{VLLM_CLIENT_ROOT}/.logs`) once it exceeds this size; the overflow is kept as `<file>.1`. |
| `LOG_RETENTION_DAYS` | `14` | Delete persistent deployment log files untouched for this many days. |
| `PODMAN_SOCK` | *(auto)* | Non-standard Podman API socket path. By default the agent probes the rootless socket (`$XDG_RUNTIME_DIR/podman/podman.sock`) and the rootful one (`/run/podman/podman.sock`). |

Expand Down
Loading