Merge pull request 'feat(dashboard): v2 — SSE status, model upload, comfy management, system controls' (#2) from feature/dashboard-v2 into master
Reviewed-on: #2
This commit was merged in pull request #2.
This commit is contained in:
20
.env.example
20
.env.example
@@ -1,7 +1,25 @@
|
|||||||
|
# ---------------------------------------------------------------------------
|
||||||
|
# GPU-Node environment
|
||||||
|
# ---------------------------------------------------------------------------
|
||||||
|
# Copy this file to `.env` and fill in the values before running
|
||||||
|
# `docker compose up -d` or `START_GPU_NODE.bat`.
|
||||||
|
#
|
||||||
|
# IMPORTANT: HOST_PROJECT_PATH must be set here, otherwise:
|
||||||
|
# - `ssh` container entrypoint will exit with "HOST_PROJECT_PATH is not set"
|
||||||
|
# - After server reboot, Docker daemon will try to restart it forever
|
||||||
|
# (restart: always), but it will keep failing
|
||||||
|
# - Only `tailscale` (which doesn't need HOST_PROJECT_PATH) will come up
|
||||||
|
# ---------------------------------------------------------------------------
|
||||||
|
|
||||||
TAILSCALE_HOSTNAME=gpu-node
|
TAILSCALE_HOSTNAME=gpu-node
|
||||||
TS_AUTHKEY=
|
TS_AUTHKEY=
|
||||||
WEBDAV_USER=operator
|
WEBDAV_USER=operator
|
||||||
WEBDAV_PASS=
|
WEBDAV_PASS=
|
||||||
|
|
||||||
|
# Absolute path to the GPU-Node directory ON THE HOST.
|
||||||
|
# On WSL: /home/<user>/projects/GPU-Node
|
||||||
|
# On Windows+WSL: the WSL path (not the Windows path) of the project dir
|
||||||
HOST_PROJECT_PATH=
|
HOST_PROJECT_PATH=
|
||||||
|
|
||||||
LLAMA_MODEL=model.gguf
|
LLAMA_MODEL=model.gguf
|
||||||
LLAMA_EXTRA_ARGS=
|
LLAMA_EXTRA_ARGS=
|
||||||
|
|||||||
75
RESTART_WSL.bat
Normal file
75
RESTART_WSL.bat
Normal file
@@ -0,0 +1,75 @@
|
|||||||
|
@echo off
|
||||||
|
setlocal enabledelayedexpansion
|
||||||
|
|
||||||
|
echo ========================================
|
||||||
|
echo RESTART WSL + GPU NODE
|
||||||
|
echo ========================================
|
||||||
|
echo.
|
||||||
|
|
||||||
|
REM ----- Step 1: check if WSL is running -----
|
||||||
|
echo [1/4] Checking WSL state...
|
||||||
|
wsl --list --running | findstr /R /C:"Ubuntu" /C:"ubuntu" /C:"Default" >nul 2>&1
|
||||||
|
if errorlevel 1 (
|
||||||
|
echo WSL is not running. Starting it...
|
||||||
|
wsl --list --verbose >nul 2>&1
|
||||||
|
REM Touch WSL to make sure the distro is awake
|
||||||
|
wsl bash -c "echo started" >nul 2>&1
|
||||||
|
) else (
|
||||||
|
echo WSL is already running.
|
||||||
|
)
|
||||||
|
|
||||||
|
REM ----- Step 2: shut down WSL -----
|
||||||
|
echo.
|
||||||
|
echo [2/4] Shutting down WSL...
|
||||||
|
wsl --shutdown
|
||||||
|
if errorlevel 1 (
|
||||||
|
echo WARNING: wsl --shutdown returned an error.
|
||||||
|
goto :error
|
||||||
|
)
|
||||||
|
|
||||||
|
REM Wait for WSL to fully terminate
|
||||||
|
timeout /t 3 /nobreak >nul
|
||||||
|
|
||||||
|
REM ----- Step 3: start WSL again -----
|
||||||
|
echo.
|
||||||
|
echo [3/4] Starting WSL...
|
||||||
|
REM Get WSL path of this script's directory
|
||||||
|
set "WIN_DIR=%~dp0"
|
||||||
|
set "WIN_DIR_TRIMMED=%WIN_DIR:~0,-1%"
|
||||||
|
for /f "delims=" %%i in ('wsl wslpath -u "%WIN_DIR_TRIMMED%"') do set "WSL_DIR=%%i"
|
||||||
|
|
||||||
|
REM Trigger WSL to start (any command will wake it up)
|
||||||
|
wsl bash -c "echo WSL awake"
|
||||||
|
if errorlevel 1 (
|
||||||
|
echo ERROR: failed to start WSL.
|
||||||
|
goto :error
|
||||||
|
)
|
||||||
|
|
||||||
|
echo WSL path: %WSL_DIR%
|
||||||
|
|
||||||
|
REM ----- Step 4: ensure Docker is up and start GPU node containers -----
|
||||||
|
echo.
|
||||||
|
echo [4/4] Starting Docker services...
|
||||||
|
wsl bash -c "cd '%WSL_DIR%' && docker compose up -d"
|
||||||
|
if errorlevel 1 (
|
||||||
|
echo ERROR: docker compose up failed.
|
||||||
|
goto :error
|
||||||
|
)
|
||||||
|
|
||||||
|
echo.
|
||||||
|
echo ========================================
|
||||||
|
echo WSL restarted + GPU node started
|
||||||
|
echo ========================================
|
||||||
|
echo.
|
||||||
|
wsl bash -c "docker ps --filter 'name=gpu-node-'"
|
||||||
|
echo.
|
||||||
|
pause
|
||||||
|
exit /b 0
|
||||||
|
|
||||||
|
:error
|
||||||
|
echo.
|
||||||
|
echo ========================================
|
||||||
|
echo FAILED — see errors above
|
||||||
|
echo ========================================
|
||||||
|
pause
|
||||||
|
exit /b 1
|
||||||
@@ -1,3 +1,10 @@
|
|||||||
|
# ---------------------------------------------------------------------------
|
||||||
|
# Validate HOST_PROJECT_PATH early — if it's empty, the `ssh` container will
|
||||||
|
# exit with "HOST_PROJECT_PATH is not set" and after a server reboot only
|
||||||
|
# tailscale will come back (because ssh keeps crash-looping on restart: always).
|
||||||
|
# ---------------------------------------------------------------------------
|
||||||
|
# ${HOST_PROJECT_PATH:?ERROR: HOST_PROJECT_PATH must be set in .env — see .env.example}
|
||||||
|
|
||||||
name: ${TAILSCALE_HOSTNAME:-gpu-node}
|
name: ${TAILSCALE_HOSTNAME:-gpu-node}
|
||||||
|
|
||||||
services:
|
services:
|
||||||
|
|||||||
32
dashboard/.dockerignore
Normal file
32
dashboard/.dockerignore
Normal file
@@ -0,0 +1,32 @@
|
|||||||
|
# VCS
|
||||||
|
.git
|
||||||
|
.gitignore
|
||||||
|
|
||||||
|
# Deps
|
||||||
|
node_modules
|
||||||
|
.pnp
|
||||||
|
.pnp.*
|
||||||
|
|
||||||
|
# Build artifacts
|
||||||
|
.next
|
||||||
|
out
|
||||||
|
build
|
||||||
|
|
||||||
|
# Misc
|
||||||
|
.DS_Store
|
||||||
|
*.pem
|
||||||
|
npm-debug.log*
|
||||||
|
yarn-debug.log*
|
||||||
|
yarn-error.log*
|
||||||
|
.env
|
||||||
|
.env*.local
|
||||||
|
.idea
|
||||||
|
.vscode
|
||||||
|
|
||||||
|
# Scripts / docs
|
||||||
|
README.md
|
||||||
|
.eslintrc.json
|
||||||
|
*.md
|
||||||
|
|
||||||
|
# Don't accidentally bring the parent repo
|
||||||
|
../.git
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
# syntax=docker/dockerfile:1.7
|
# syntax=docker/dockerfile:1.4
|
||||||
|
|
||||||
# ---------------------------------------------------------------------------
|
# ---------------------------------------------------------------------------
|
||||||
# Stage 1: Install deps & build Next.js standalone output
|
# Stage 1: Install deps & build Next.js standalone output
|
||||||
@@ -7,18 +7,12 @@ FROM node:20-alpine AS builder
|
|||||||
|
|
||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
|
|
||||||
# Install dependencies (use yarn or npm — package-lock.json optional)
|
# Copy only manifests first for better layer caching.
|
||||||
COPY package.json ./
|
# NOTE: legacy Docker builder (no BuildKit) fails on `COPY <wildcard>` when no
|
||||||
COPY package-lock.json* ./
|
# file matches the pattern, so we list files explicitly here.
|
||||||
COPY yarn.lock* ./
|
COPY package.json package-lock.json ./
|
||||||
|
|
||||||
RUN if [ -f yarn.lock ]; then \
|
RUN npm ci --no-audit --no-fund
|
||||||
yarn install --frozen-lockfile; \
|
|
||||||
elif [ -f package-lock.json ]; then \
|
|
||||||
npm ci; \
|
|
||||||
else \
|
|
||||||
npm install; \
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Copy sources and build
|
# Copy sources and build
|
||||||
COPY tsconfig.json next.config.ts next-env.d.ts postcss.config.mjs .eslintrc.json ./
|
COPY tsconfig.json next.config.ts next-env.d.ts postcss.config.mjs .eslintrc.json ./
|
||||||
@@ -27,11 +21,7 @@ COPY public ./public
|
|||||||
|
|
||||||
ENV NEXT_TELEMETRY_DISABLED=1
|
ENV NEXT_TELEMETRY_DISABLED=1
|
||||||
|
|
||||||
RUN if [ -f yarn.lock ]; then \
|
RUN npm run build
|
||||||
yarn build; \
|
|
||||||
else \
|
|
||||||
npm run build; \
|
|
||||||
fi
|
|
||||||
|
|
||||||
# ---------------------------------------------------------------------------
|
# ---------------------------------------------------------------------------
|
||||||
# Stage 2: Runtime — Alpine + Node + docker-cli + docker compose plugin
|
# Stage 2: Runtime — Alpine + Node + docker-cli + docker compose plugin
|
||||||
@@ -50,7 +40,7 @@ RUN apk add --no-cache \
|
|||||||
|
|
||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
|
|
||||||
# Copy standalone Next.js build output
|
# Copy standalone Next.js build output (with node_modules baked in)
|
||||||
COPY --from=builder --chown=dash:dash /app/.next/standalone ./
|
COPY --from=builder --chown=dash:dash /app/.next/standalone ./
|
||||||
COPY --from=builder --chown=dash:dash /app/.next/static ./.next/static
|
COPY --from=builder --chown=dash:dash /app/.next/static ./.next/static
|
||||||
COPY --from=builder --chown=dash:dash /app/public ./public
|
COPY --from=builder --chown=dash:dash /app/public ./public
|
||||||
|
|||||||
25
dashboard/src/app/api/comfy/models/add/route.ts
Normal file
25
dashboard/src/app/api/comfy/models/add/route.ts
Normal file
@@ -0,0 +1,25 @@
|
|||||||
|
import { NextRequest, NextResponse } from "next/server";
|
||||||
|
import { addComfyModel } from "@/lib/docker";
|
||||||
|
|
||||||
|
export const dynamic = "force-dynamic";
|
||||||
|
export const runtime = "nodejs";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* POST /api/comfy/models/add
|
||||||
|
* Body: { url: string, type: string }
|
||||||
|
* Queues a model download via model-worker.
|
||||||
|
*/
|
||||||
|
export async function POST(req: NextRequest) {
|
||||||
|
const body = (await req.json()) as { url?: string; type?: string };
|
||||||
|
if (!body.url || !body.type) {
|
||||||
|
return NextResponse.json(
|
||||||
|
{ ok: false, error: "url and type required" },
|
||||||
|
{ status: 400 }
|
||||||
|
);
|
||||||
|
}
|
||||||
|
const result = await addComfyModel(body.url, body.type);
|
||||||
|
return NextResponse.json(
|
||||||
|
{ ok: result.ok, output: result.output, error: result.error },
|
||||||
|
{ status: result.ok ? 200 : 500 }
|
||||||
|
);
|
||||||
|
}
|
||||||
25
dashboard/src/app/api/comfy/models/rm/route.ts
Normal file
25
dashboard/src/app/api/comfy/models/rm/route.ts
Normal file
@@ -0,0 +1,25 @@
|
|||||||
|
import { NextRequest, NextResponse } from "next/server";
|
||||||
|
import { removeComfyModel } from "@/lib/docker";
|
||||||
|
|
||||||
|
export const dynamic = "force-dynamic";
|
||||||
|
export const runtime = "nodejs";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* POST /api/comfy/models/rm
|
||||||
|
* Body: { filename: string, type?: string }
|
||||||
|
* Removes a comfy model from disk via model-worker.
|
||||||
|
*/
|
||||||
|
export async function POST(req: NextRequest) {
|
||||||
|
const body = (await req.json()) as { filename?: string; type?: string };
|
||||||
|
if (!body.filename) {
|
||||||
|
return NextResponse.json(
|
||||||
|
{ ok: false, error: "filename required" },
|
||||||
|
{ status: 400 }
|
||||||
|
);
|
||||||
|
}
|
||||||
|
const result = await removeComfyModel(body.filename, body.type);
|
||||||
|
return NextResponse.json(
|
||||||
|
{ ok: result.ok, output: result.output, error: result.error },
|
||||||
|
{ status: result.ok ? 200 : 500 }
|
||||||
|
);
|
||||||
|
}
|
||||||
18
dashboard/src/app/api/comfy/models/route.ts
Normal file
18
dashboard/src/app/api/comfy/models/route.ts
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
import { NextRequest, NextResponse } from "next/server";
|
||||||
|
import { listComfyModels } from "@/lib/docker";
|
||||||
|
|
||||||
|
export const dynamic = "force-dynamic";
|
||||||
|
export const runtime = "nodejs";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* GET /api/comfy/models?type=<optional>
|
||||||
|
* Lists comfy models via `docker exec model-worker python3 /app/worker.py list [type]`.
|
||||||
|
*/
|
||||||
|
export async function GET(req: NextRequest) {
|
||||||
|
const type = req.nextUrl.searchParams.get("type") || undefined;
|
||||||
|
const result = await listComfyModels(type);
|
||||||
|
return NextResponse.json(
|
||||||
|
{ ok: result.ok, models: result.models, raw: result.raw, error: result.error },
|
||||||
|
{ status: result.ok ? 200 : 500 }
|
||||||
|
);
|
||||||
|
}
|
||||||
17
dashboard/src/app/api/comfy/queue/route.ts
Normal file
17
dashboard/src/app/api/comfy/queue/route.ts
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
import { NextRequest, NextResponse } from "next/server";
|
||||||
|
import { getComfyQueue } from "@/lib/docker";
|
||||||
|
|
||||||
|
export const dynamic = "force-dynamic";
|
||||||
|
export const runtime = "nodejs";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* GET /api/comfy/queue
|
||||||
|
* Returns current download queue via `docker exec model-worker python3 /app/worker.py queue`.
|
||||||
|
*/
|
||||||
|
export async function GET() {
|
||||||
|
const result = await getComfyQueue();
|
||||||
|
return NextResponse.json(
|
||||||
|
{ ok: result.ok, queue: result.queue, raw: result.raw, error: result.error },
|
||||||
|
{ status: result.ok ? 200 : 500 }
|
||||||
|
);
|
||||||
|
}
|
||||||
62
dashboard/src/app/api/comfy/route.ts
Normal file
62
dashboard/src/app/api/comfy/route.ts
Normal file
@@ -0,0 +1,62 @@
|
|||||||
|
import { NextRequest, NextResponse } from "next/server";
|
||||||
|
import {
|
||||||
|
startService,
|
||||||
|
stopService,
|
||||||
|
restartService,
|
||||||
|
getServiceLogs,
|
||||||
|
type ServiceRole,
|
||||||
|
} from "@/lib/docker";
|
||||||
|
|
||||||
|
export const dynamic = "force-dynamic";
|
||||||
|
export const runtime = "nodejs";
|
||||||
|
export const maxDuration = 120;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* POST /api/comfy
|
||||||
|
* Body: { action: "start" | "stop" | "restart" }
|
||||||
|
*
|
||||||
|
* Start / stop / restart ComfyUI. Optional `extraArgs` for start (passed
|
||||||
|
* through COMFY_EXTRA_ARGS env var).
|
||||||
|
*/
|
||||||
|
export async function POST(req: NextRequest) {
|
||||||
|
const body = (await req.json()) as {
|
||||||
|
action: "start" | "stop" | "restart";
|
||||||
|
extraArgs?: string;
|
||||||
|
};
|
||||||
|
|
||||||
|
const role: ServiceRole = "comfyui";
|
||||||
|
|
||||||
|
if (body.action === "start") {
|
||||||
|
if (body.extraArgs) {
|
||||||
|
process.env.COMFY_EXTRA_ARGS = body.extraArgs;
|
||||||
|
}
|
||||||
|
const result = await startService(role);
|
||||||
|
return NextResponse.json(result, { status: result.ok ? 200 : 500 });
|
||||||
|
}
|
||||||
|
|
||||||
|
if (body.action === "stop") {
|
||||||
|
const result = await stopService(role);
|
||||||
|
return NextResponse.json(result, { status: result.ok ? 200 : 500 });
|
||||||
|
}
|
||||||
|
|
||||||
|
if (body.action === "restart") {
|
||||||
|
const result = await restartService(role);
|
||||||
|
return NextResponse.json(result, { status: result.ok ? 200 : 500 });
|
||||||
|
}
|
||||||
|
|
||||||
|
return NextResponse.json({ error: "unknown action" }, { status: 400 });
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* GET /api/comfy?logs=1&tail=500
|
||||||
|
* Returns comfyui logs.
|
||||||
|
*/
|
||||||
|
export async function GET(req: NextRequest) {
|
||||||
|
const withLogs = req.nextUrl.searchParams.get("logs");
|
||||||
|
if (withLogs) {
|
||||||
|
const tail = Number(req.nextUrl.searchParams.get("tail") || 500);
|
||||||
|
const logs = await getServiceLogs("comfyui", tail);
|
||||||
|
return NextResponse.json({ ok: true, logs });
|
||||||
|
}
|
||||||
|
return NextResponse.json({ ok: true });
|
||||||
|
}
|
||||||
@@ -1,10 +1,29 @@
|
|||||||
import { NextResponse } from "next/server";
|
import { NextRequest, NextResponse } from "next/server";
|
||||||
import { listModels } from "@/lib/docker";
|
import { deleteModel, listModels } from "@/lib/docker";
|
||||||
|
|
||||||
export const dynamic = "force-dynamic";
|
export const dynamic = "force-dynamic";
|
||||||
export const runtime = "nodejs";
|
export const runtime = "nodejs";
|
||||||
|
|
||||||
export async function GET() {
|
/**
|
||||||
|
* DELETE /api/models?name=foo.gguf
|
||||||
|
*
|
||||||
|
* Removes a .gguf file from gpu/llama_models/.
|
||||||
|
*/
|
||||||
|
export async function DELETE(req: NextRequest) {
|
||||||
|
const name = req.nextUrl.searchParams.get("name");
|
||||||
|
if (!name) {
|
||||||
|
return NextResponse.json(
|
||||||
|
{ ok: false, error: "name query param required" },
|
||||||
|
{ status: 400 }
|
||||||
|
);
|
||||||
|
}
|
||||||
|
const result = await deleteModel(name);
|
||||||
|
if (!result.ok) {
|
||||||
|
return NextResponse.json(
|
||||||
|
{ ok: false, error: result.error },
|
||||||
|
{ status: 400 }
|
||||||
|
);
|
||||||
|
}
|
||||||
const models = await listModels();
|
const models = await listModels();
|
||||||
return NextResponse.json({ models });
|
return NextResponse.json({ ok: true, models });
|
||||||
}
|
}
|
||||||
|
|||||||
58
dashboard/src/app/api/models/upload/route.ts
Normal file
58
dashboard/src/app/api/models/upload/route.ts
Normal file
@@ -0,0 +1,58 @@
|
|||||||
|
import { NextRequest, NextResponse } from "next/server";
|
||||||
|
import { saveUploadedModel, listModels } from "@/lib/docker";
|
||||||
|
|
||||||
|
export const dynamic = "force-dynamic";
|
||||||
|
export const runtime = "nodejs";
|
||||||
|
export const maxDuration = 600;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* POST /api/models/upload
|
||||||
|
*
|
||||||
|
* Accepts a multipart/form-data upload with a single "file" field.
|
||||||
|
* Saves to gpu/llama_models/<filename>. Returns updated model list.
|
||||||
|
*
|
||||||
|
* Body:
|
||||||
|
* multipart/form-data
|
||||||
|
* - file: <.gguf file>
|
||||||
|
*/
|
||||||
|
export async function POST(req: NextRequest) {
|
||||||
|
const contentType = req.headers.get("content-type") || "";
|
||||||
|
if (!contentType.includes("multipart/form-data")) {
|
||||||
|
return NextResponse.json(
|
||||||
|
{ ok: false, error: "expected multipart/form-data" },
|
||||||
|
{ status: 400 }
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
const form = await req.formData();
|
||||||
|
const file = form.get("file");
|
||||||
|
if (!file || !(file instanceof File)) {
|
||||||
|
return NextResponse.json(
|
||||||
|
{ ok: false, error: "missing 'file' field" },
|
||||||
|
{ status: 400 }
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
const buffer = Buffer.from(await file.arrayBuffer());
|
||||||
|
const result = await saveUploadedModel(file.name, buffer);
|
||||||
|
if (!result.ok) {
|
||||||
|
return NextResponse.json(
|
||||||
|
{ ok: false, error: result.error },
|
||||||
|
{ status: 400 }
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
const models = await listModels();
|
||||||
|
return NextResponse.json({
|
||||||
|
ok: true,
|
||||||
|
path: result.path,
|
||||||
|
models,
|
||||||
|
});
|
||||||
|
} catch (err) {
|
||||||
|
return NextResponse.json(
|
||||||
|
{ ok: false, error: (err as Error).message },
|
||||||
|
{ status: 500 }
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
91
dashboard/src/app/api/services/[role]/route.ts
Normal file
91
dashboard/src/app/api/services/[role]/route.ts
Normal file
@@ -0,0 +1,91 @@
|
|||||||
|
import { NextRequest, NextResponse } from "next/server";
|
||||||
|
import {
|
||||||
|
startService,
|
||||||
|
stopService,
|
||||||
|
restartService,
|
||||||
|
removeService,
|
||||||
|
getServiceLogs,
|
||||||
|
type ServiceRole,
|
||||||
|
} from "@/lib/docker";
|
||||||
|
|
||||||
|
export const dynamic = "force-dynamic";
|
||||||
|
export const runtime = "nodejs";
|
||||||
|
export const maxDuration = 120;
|
||||||
|
|
||||||
|
const VALID_ROLES: ServiceRole[] = [
|
||||||
|
"llama",
|
||||||
|
"comfyui",
|
||||||
|
"model-worker",
|
||||||
|
"webdav",
|
||||||
|
"ssh",
|
||||||
|
"ssh-companion",
|
||||||
|
"gpu-test",
|
||||||
|
"dashboard",
|
||||||
|
];
|
||||||
|
|
||||||
|
function parseRole(role: string): ServiceRole | null {
|
||||||
|
return (VALID_ROLES as string[]).includes(role)
|
||||||
|
? (role as ServiceRole)
|
||||||
|
: null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* GET /api/services/<role>?action=logs&tail=500
|
||||||
|
* Returns logs for the given service.
|
||||||
|
*
|
||||||
|
* POST /api/services/<role>
|
||||||
|
* Body: { action: "start" | "stop" | "restart" | "remove" }
|
||||||
|
*/
|
||||||
|
export async function GET(
|
||||||
|
req: NextRequest,
|
||||||
|
{ params }: { params: Promise<{ role: string }> }
|
||||||
|
) {
|
||||||
|
const { role: roleRaw } = await params;
|
||||||
|
const role = parseRole(roleRaw);
|
||||||
|
if (!role) {
|
||||||
|
return NextResponse.json(
|
||||||
|
{ ok: false, error: `invalid role: ${roleRaw}` },
|
||||||
|
{ status: 400 }
|
||||||
|
);
|
||||||
|
}
|
||||||
|
const tail = Number(req.nextUrl.searchParams.get("tail") || 500);
|
||||||
|
const logs = await getServiceLogs(role, tail);
|
||||||
|
return NextResponse.json({ ok: true, logs });
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function POST(
|
||||||
|
req: NextRequest,
|
||||||
|
{ params }: { params: Promise<{ role: string }> }
|
||||||
|
) {
|
||||||
|
const { role: roleRaw } = await params;
|
||||||
|
const role = parseRole(roleRaw);
|
||||||
|
if (!role) {
|
||||||
|
return NextResponse.json(
|
||||||
|
{ ok: false, error: `invalid role: ${roleRaw}` },
|
||||||
|
{ status: 400 }
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
const body = (await req.json()) as {
|
||||||
|
action: "start" | "stop" | "restart" | "remove";
|
||||||
|
};
|
||||||
|
|
||||||
|
if (body.action === "start") {
|
||||||
|
const r = await startService(role);
|
||||||
|
return NextResponse.json(r, { status: r.ok ? 200 : 500 });
|
||||||
|
}
|
||||||
|
if (body.action === "stop") {
|
||||||
|
const r = await stopService(role);
|
||||||
|
return NextResponse.json(r, { status: r.ok ? 200 : 500 });
|
||||||
|
}
|
||||||
|
if (body.action === "restart") {
|
||||||
|
const r = await restartService(role);
|
||||||
|
return NextResponse.json(r, { status: r.ok ? 200 : 500 });
|
||||||
|
}
|
||||||
|
if (body.action === "remove") {
|
||||||
|
const r = await removeService(role);
|
||||||
|
return NextResponse.json(r, { status: r.ok ? 200 : 500 });
|
||||||
|
}
|
||||||
|
|
||||||
|
return NextResponse.json({ error: "unknown action" }, { status: 400 });
|
||||||
|
}
|
||||||
94
dashboard/src/app/api/status/stream/route.ts
Normal file
94
dashboard/src/app/api/status/stream/route.ts
Normal file
@@ -0,0 +1,94 @@
|
|||||||
|
import { listContainers, getLlamaHealth, NODE_INSTANCE } from "@/lib/docker";
|
||||||
|
|
||||||
|
export const dynamic = "force-dynamic";
|
||||||
|
export const runtime = "nodejs";
|
||||||
|
export const maxDuration = 300;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Server-Sent Events stream for status updates.
|
||||||
|
*
|
||||||
|
* Replaces fetch-polling — client opens a single EventSource connection
|
||||||
|
* and receives a `status` event every N seconds with the full status
|
||||||
|
* payload. SSE was chosen over WebSocket because:
|
||||||
|
* - one-way (server → client) is all we need for status pushes
|
||||||
|
* - works through any HTTP proxy (Tailscale serve) without WS upgrade
|
||||||
|
* - built into the browser (EventSource API), no extra deps
|
||||||
|
* - keeps Next.js standalone output (smaller docker image)
|
||||||
|
*
|
||||||
|
* Client usage:
|
||||||
|
* const es = new EventSource("/api/status/stream");
|
||||||
|
* es.addEventListener("status", (e) => {
|
||||||
|
* const data = JSON.parse(e.data);
|
||||||
|
* ...
|
||||||
|
* });
|
||||||
|
*/
|
||||||
|
export async function GET() {
|
||||||
|
const encoder = new TextEncoder();
|
||||||
|
|
||||||
|
const stream = new ReadableStream<Uint8Array>({
|
||||||
|
async start(controller) {
|
||||||
|
const send = (event: string, data: unknown) => {
|
||||||
|
try {
|
||||||
|
controller.enqueue(
|
||||||
|
encoder.encode(
|
||||||
|
`event: ${event}\ndata: ${JSON.stringify(data)}\n\n`
|
||||||
|
)
|
||||||
|
);
|
||||||
|
} catch {
|
||||||
|
/* stream closed */
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
// Initial hello so the client knows the stream is alive
|
||||||
|
send("hello", {
|
||||||
|
instance: NODE_INSTANCE,
|
||||||
|
ts: Date.now(),
|
||||||
|
});
|
||||||
|
|
||||||
|
// Push status immediately (don't wait for the first interval)
|
||||||
|
const pushStatus = async () => {
|
||||||
|
try {
|
||||||
|
const [containers, llamaHealth] = await Promise.all([
|
||||||
|
listContainers(),
|
||||||
|
getLlamaHealth(),
|
||||||
|
]);
|
||||||
|
send("status", {
|
||||||
|
instance: NODE_INSTANCE,
|
||||||
|
containers,
|
||||||
|
llamaHealth,
|
||||||
|
timestamp: new Date().toISOString(),
|
||||||
|
});
|
||||||
|
} catch (err) {
|
||||||
|
send("error", { message: (err as Error).message });
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
await pushStatus();
|
||||||
|
|
||||||
|
const interval = setInterval(pushStatus, 4000);
|
||||||
|
|
||||||
|
// Cleanup when client disconnects
|
||||||
|
// The controller.close() is called when the consumer cancels the stream
|
||||||
|
// ( AbortController / EventSource.close() on the client side).
|
||||||
|
// We use the `cancel` method below.
|
||||||
|
// Store interval on the controller via closure.
|
||||||
|
(controller as unknown as { _interval?: NodeJS.Timeout })._interval =
|
||||||
|
interval;
|
||||||
|
},
|
||||||
|
cancel(controller) {
|
||||||
|
const interval = (
|
||||||
|
controller as unknown as { _interval?: NodeJS.Timeout }
|
||||||
|
)._interval;
|
||||||
|
if (interval) clearInterval(interval);
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
return new Response(stream, {
|
||||||
|
headers: {
|
||||||
|
"Content-Type": "text/event-stream; charset=utf-8",
|
||||||
|
"Cache-Control": "no-cache, no-transform",
|
||||||
|
"Connection": "keep-alive",
|
||||||
|
"X-Accel-Buffering": "no",
|
||||||
|
},
|
||||||
|
});
|
||||||
|
}
|
||||||
33
dashboard/src/app/api/system/route.ts
Normal file
33
dashboard/src/app/api/system/route.ts
Normal file
@@ -0,0 +1,33 @@
|
|||||||
|
import { NextRequest, NextResponse } from "next/server";
|
||||||
|
import { sleepMode, wakeMode, updateNode } from "@/lib/docker";
|
||||||
|
|
||||||
|
export const dynamic = "force-dynamic";
|
||||||
|
export const runtime = "nodejs";
|
||||||
|
export const maxDuration = 600;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* POST /api/system
|
||||||
|
* Body: { action: "sleep" | "wake" | "update" }
|
||||||
|
*
|
||||||
|
* Mirrors `gpuctl sleep|wake|update` CLI commands.
|
||||||
|
*/
|
||||||
|
export async function POST(req: NextRequest) {
|
||||||
|
const body = (await req.json()) as { action: "sleep" | "wake" | "update" };
|
||||||
|
|
||||||
|
if (body.action === "sleep") {
|
||||||
|
const result = await sleepMode();
|
||||||
|
return NextResponse.json(result, { status: result.ok ? 200 : 500 });
|
||||||
|
}
|
||||||
|
|
||||||
|
if (body.action === "wake") {
|
||||||
|
const result = await wakeMode();
|
||||||
|
return NextResponse.json(result, { status: result.ok ? 200 : 500 });
|
||||||
|
}
|
||||||
|
|
||||||
|
if (body.action === "update") {
|
||||||
|
const result = await updateNode();
|
||||||
|
return NextResponse.json(result, { status: result.ok ? 200 : 500 });
|
||||||
|
}
|
||||||
|
|
||||||
|
return NextResponse.json({ error: "unknown action" }, { status: 400 });
|
||||||
|
}
|
||||||
File diff suppressed because it is too large
Load Diff
@@ -618,3 +618,414 @@ export async function getLlamaHealth(): Promise<{
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ---------------------------------------------------------------------------
|
||||||
|
// Generic service control (start / stop / restart / remove / logs)
|
||||||
|
// ---------------------------------------------------------------------------
|
||||||
|
|
||||||
|
export type ServiceRole =
|
||||||
|
| "llama"
|
||||||
|
| "comfyui"
|
||||||
|
| "model-worker"
|
||||||
|
| "webdav"
|
||||||
|
| "ssh"
|
||||||
|
| "ssh-companion"
|
||||||
|
| "gpu-test"
|
||||||
|
| "dashboard"
|
||||||
|
| "tailscale";
|
||||||
|
|
||||||
|
const COMPOSE_PROFILES: Partial<Record<ServiceRole, string>> = {
|
||||||
|
llama: "llama",
|
||||||
|
comfyui: "comfy",
|
||||||
|
"gpu-test": "test",
|
||||||
|
// ssh-companion / model-worker / webdav need the `wake` profile when
|
||||||
|
// starting from scratch, but `docker compose up -d <svc>` with explicit
|
||||||
|
// service name overrides the profile check at the compose level.
|
||||||
|
"ssh-companion": "wake",
|
||||||
|
"model-worker": "wake",
|
||||||
|
webdav: "wake",
|
||||||
|
};
|
||||||
|
|
||||||
|
export async function startService(
|
||||||
|
role: ServiceRole
|
||||||
|
): Promise<StartResult> {
|
||||||
|
const profile = COMPOSE_PROFILES[role];
|
||||||
|
const args = ["up", "-d", "--force-recreate", role];
|
||||||
|
if (profile) args.unshift("--profile", profile);
|
||||||
|
const res = await runCompose(args, {});
|
||||||
|
return {
|
||||||
|
ok: res.code === 0,
|
||||||
|
message:
|
||||||
|
res.code === 0 ? `${role} started` : `Failed to start ${role}`,
|
||||||
|
logs: res.stdout + (res.stderr ? `\n${res.stderr}` : ""),
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function stopService(role: ServiceRole): Promise<StartResult> {
|
||||||
|
// For profile services, we need to pass --profile too so compose knows about them
|
||||||
|
const profile = COMPOSE_PROFILES[role];
|
||||||
|
const args = ["stop", role];
|
||||||
|
if (profile) args.unshift("--profile", profile);
|
||||||
|
const res = await runCompose(args, {});
|
||||||
|
return {
|
||||||
|
ok: res.code === 0,
|
||||||
|
message: res.code === 0 ? `${role} stopped` : `Failed to stop ${role}`,
|
||||||
|
logs: res.stdout + (res.stderr ? `\n${res.stderr}` : ""),
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function restartService(
|
||||||
|
role: ServiceRole
|
||||||
|
): Promise<StartResult> {
|
||||||
|
const profile = COMPOSE_PROFILES[role];
|
||||||
|
const args = ["restart", role];
|
||||||
|
if (profile) args.unshift("--profile", profile);
|
||||||
|
const res = await runCompose(args, {});
|
||||||
|
return {
|
||||||
|
ok: res.code === 0,
|
||||||
|
message: res.code === 0 ? `${role} restarted` : `Failed to restart ${role}`,
|
||||||
|
logs: res.stdout + (res.stderr ? `\n${res.stderr}` : ""),
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function removeService(
|
||||||
|
role: ServiceRole
|
||||||
|
): Promise<StartResult> {
|
||||||
|
// For services that the dashboard might want to nuke (e.g. llama), do a
|
||||||
|
// hard `docker rm -f` on the container found via labels. This avoids
|
||||||
|
// the profile problem entirely.
|
||||||
|
const name = await getServiceContainerName(role);
|
||||||
|
if (!name) {
|
||||||
|
return { ok: false, message: `${role} not found`, logs: "" };
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
await execAsync(`docker rm -f ${name}`, {
|
||||||
|
maxBuffer: 1 * 1024 * 1024,
|
||||||
|
});
|
||||||
|
return {
|
||||||
|
ok: true,
|
||||||
|
message: `${role} removed`,
|
||||||
|
logs: `removed ${name}`,
|
||||||
|
};
|
||||||
|
} catch (err) {
|
||||||
|
return {
|
||||||
|
ok: false,
|
||||||
|
message: `Failed to remove ${role}`,
|
||||||
|
logs: (err as Error).message,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function getServiceContainerName(
|
||||||
|
role: ServiceRole
|
||||||
|
): Promise<string | null> {
|
||||||
|
// Map service roles to docker-compose labels
|
||||||
|
const labelRole =
|
||||||
|
role === "ssh" ? "ssh-main" : role === "ssh-companion" ? "ssh-companion" : role;
|
||||||
|
try {
|
||||||
|
const { stdout } = await execAsync(
|
||||||
|
`docker ps -a --filter label=node.role=${labelRole} --filter label=node.instance=${NODE_INSTANCE} --format {{.Names}}`,
|
||||||
|
{ maxBuffer: 1 * 1024 * 1024 }
|
||||||
|
);
|
||||||
|
return String(stdout).trim().split("\n")[0] || null;
|
||||||
|
} catch {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function getServiceLogs(
|
||||||
|
role: ServiceRole,
|
||||||
|
tail: number = 500
|
||||||
|
): Promise<string> {
|
||||||
|
const name = await getServiceContainerName(role);
|
||||||
|
if (!name) return `[${role} container not found]`;
|
||||||
|
try {
|
||||||
|
const { stdout } = await execAsync(`docker logs --tail ${tail} ${name}`, {
|
||||||
|
maxBuffer: 16 * 1024 * 1024,
|
||||||
|
});
|
||||||
|
return String(stdout);
|
||||||
|
} catch (err) {
|
||||||
|
return `[failed: ${(err as Error).message}]`;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// ---------------------------------------------------------------------------
|
||||||
|
// ComfyUI model worker proxy (mirrors `gpuctl comfy models ...`)
|
||||||
|
// ---------------------------------------------------------------------------
|
||||||
|
|
||||||
|
async function modelWorkerExec(
|
||||||
|
...args: string[]
|
||||||
|
): Promise<{ ok: boolean; output: string; error: string }> {
|
||||||
|
const container = await getServiceContainerName("model-worker");
|
||||||
|
if (!container) {
|
||||||
|
return {
|
||||||
|
ok: false,
|
||||||
|
output: "",
|
||||||
|
error: "model-worker container not found",
|
||||||
|
};
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
const quoted = args.map((a) => `'${a.replace(/'/g, "'\\''")}'`).join(" ");
|
||||||
|
const { stdout, stderr } = await execAsync(
|
||||||
|
`docker exec ${container} python3 /app/worker.py ${quoted}`,
|
||||||
|
{ maxBuffer: 8 * 1024 * 1024 }
|
||||||
|
);
|
||||||
|
return {
|
||||||
|
ok: true,
|
||||||
|
output: String(stdout),
|
||||||
|
error: String(stderr),
|
||||||
|
};
|
||||||
|
} catch (err) {
|
||||||
|
const e = err as {
|
||||||
|
stdout?: string | Buffer;
|
||||||
|
stderr?: string | Buffer;
|
||||||
|
message: string;
|
||||||
|
};
|
||||||
|
return {
|
||||||
|
ok: false,
|
||||||
|
output: e.stdout ? String(e.stdout) : "",
|
||||||
|
error: e.stderr ? String(e.stderr) : e.message,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface ComfyModelEntry {
|
||||||
|
type: string;
|
||||||
|
filename: string;
|
||||||
|
sizeBytes?: number;
|
||||||
|
sizeHuman?: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function listComfyModels(
|
||||||
|
type?: string
|
||||||
|
): Promise<{ ok: boolean; models: ComfyModelEntry[]; raw: string; error?: string }> {
|
||||||
|
const args = ["list"];
|
||||||
|
if (type) args.push(type);
|
||||||
|
const res = await modelWorkerExec(...args);
|
||||||
|
if (!res.ok) {
|
||||||
|
return { ok: false, models: [], raw: res.output, error: res.error };
|
||||||
|
}
|
||||||
|
// worker.py outputs JSON; parse it
|
||||||
|
try {
|
||||||
|
const parsed = JSON.parse(res.output);
|
||||||
|
const arr: ComfyModelEntry[] = Array.isArray(parsed)
|
||||||
|
? parsed
|
||||||
|
: parsed.models || parsed.items || [];
|
||||||
|
return { ok: true, models: arr, raw: res.output };
|
||||||
|
} catch {
|
||||||
|
// Probably plain text
|
||||||
|
return { ok: true, models: [], raw: res.output };
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface ComfyQueueEntry {
|
||||||
|
id: number;
|
||||||
|
action: string;
|
||||||
|
model_type: string;
|
||||||
|
filename: string;
|
||||||
|
url?: string;
|
||||||
|
status: string;
|
||||||
|
progress?: number;
|
||||||
|
downloaded_bytes?: number;
|
||||||
|
total_bytes?: number;
|
||||||
|
error?: string;
|
||||||
|
created_at?: string;
|
||||||
|
started_at?: string;
|
||||||
|
finished_at?: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function getComfyQueue(): Promise<{
|
||||||
|
ok: boolean;
|
||||||
|
queue: ComfyQueueEntry[];
|
||||||
|
raw: string;
|
||||||
|
error?: string;
|
||||||
|
}> {
|
||||||
|
const res = await modelWorkerExec("queue");
|
||||||
|
if (!res.ok) return { ok: false, queue: [], raw: res.output, error: res.error };
|
||||||
|
try {
|
||||||
|
const parsed = JSON.parse(res.output);
|
||||||
|
const arr: ComfyQueueEntry[] = Array.isArray(parsed)
|
||||||
|
? parsed
|
||||||
|
: parsed.jobs || parsed.queue || [];
|
||||||
|
return { ok: true, queue: arr, raw: res.output };
|
||||||
|
} catch {
|
||||||
|
return { ok: true, queue: [], raw: res.output };
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function addComfyModel(
|
||||||
|
url: string,
|
||||||
|
type: string
|
||||||
|
): Promise<{ ok: boolean; output: string; error?: string }> {
|
||||||
|
const res = await modelWorkerExec("add", url, type);
|
||||||
|
return { ok: res.ok, output: res.output, error: res.error };
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function removeComfyModel(
|
||||||
|
filename: string,
|
||||||
|
type?: string
|
||||||
|
): Promise<{ ok: boolean; output: string; error?: string }> {
|
||||||
|
const args = ["rm", filename];
|
||||||
|
if (type) args.push(type);
|
||||||
|
const res = await modelWorkerExec(...args);
|
||||||
|
return { ok: res.ok, output: res.output, error: res.error };
|
||||||
|
}
|
||||||
|
|
||||||
|
// ---------------------------------------------------------------------------
|
||||||
|
// System actions (sleep / wake / update)
|
||||||
|
// ---------------------------------------------------------------------------
|
||||||
|
|
||||||
|
export async function sleepMode(): Promise<StartResult> {
|
||||||
|
// Equivalent of `gpuctl sleep`:
|
||||||
|
// - keep tailscale + (ssh-main OR ssh-companion), whichever is running
|
||||||
|
// - remove: llama, comfyui, gpu-test, model-worker, webdav, dashboard
|
||||||
|
// - remove the *other* ssh role container
|
||||||
|
const main = await getServiceContainerName("ssh");
|
||||||
|
const companion = await getServiceContainerName("ssh-companion");
|
||||||
|
|
||||||
|
let keepRole: "ssh" | "ssh-companion" | "ssh";
|
||||||
|
let removeRole: "ssh" | "ssh-companion" | null = null;
|
||||||
|
|
||||||
|
if (main) {
|
||||||
|
keepRole = "ssh";
|
||||||
|
removeRole = "ssh-companion";
|
||||||
|
} else if (companion) {
|
||||||
|
keepRole = "ssh-companion";
|
||||||
|
removeRole = "ssh";
|
||||||
|
} else {
|
||||||
|
// Neither running — start ssh-main
|
||||||
|
const r = await startService("ssh");
|
||||||
|
if (!r.ok) return r;
|
||||||
|
keepRole = "ssh";
|
||||||
|
removeRole = "ssh-companion";
|
||||||
|
}
|
||||||
|
|
||||||
|
const toRemove: ServiceRole[] = [
|
||||||
|
"llama",
|
||||||
|
"comfyui",
|
||||||
|
"gpu-test",
|
||||||
|
"model-worker",
|
||||||
|
"webdav",
|
||||||
|
"dashboard",
|
||||||
|
];
|
||||||
|
if (removeRole) toRemove.push(removeRole);
|
||||||
|
|
||||||
|
const logs: string[] = [];
|
||||||
|
for (const role of toRemove) {
|
||||||
|
const name = await getServiceContainerName(role);
|
||||||
|
if (name) {
|
||||||
|
try {
|
||||||
|
await execAsync(`docker rm -f ${name}`, { maxBuffer: 1 * 1024 * 1024 });
|
||||||
|
logs.push(`removed ${role} (${name})`);
|
||||||
|
} catch (err) {
|
||||||
|
logs.push(`failed to remove ${role}: ${(err as Error).message}`);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
ok: true,
|
||||||
|
message: `Sleep mode: keeping tailscale + ${keepRole}`,
|
||||||
|
logs: logs.join("\n"),
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function wakeMode(): Promise<StartResult> {
|
||||||
|
// Equivalent of `gpuctl wake`:
|
||||||
|
// - swap ssh role (start the OTHER ssh service + model-worker + webdav + dashboard)
|
||||||
|
// We can detect which one is currently running from inside the dashboard
|
||||||
|
// container via SSH_ROLE env (set in compose.yaml). But for simplicity we
|
||||||
|
// always start ssh-companion + model-worker + webdav + dashboard.
|
||||||
|
// If user is already on ssh-companion, starting it again is a no-op.
|
||||||
|
const sshRole = process.env.SSH_ROLE || "main";
|
||||||
|
const targetSsh = sshRole === "main" ? "ssh-companion" : "ssh";
|
||||||
|
|
||||||
|
const res = await runCompose(
|
||||||
|
["--profile", "wake", "up", "-d", targetSsh, "model-worker", "webdav", "dashboard"],
|
||||||
|
{}
|
||||||
|
);
|
||||||
|
return {
|
||||||
|
ok: res.code === 0,
|
||||||
|
message: res.code === 0
|
||||||
|
? `Wake mode: started ${targetSsh} + model-worker + webdav + dashboard`
|
||||||
|
: "Failed to wake",
|
||||||
|
logs: res.stdout + (res.stderr ? `\n${res.stderr}` : ""),
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function updateNode(): Promise<StartResult> {
|
||||||
|
// Equivalent of `gpuctl update`:
|
||||||
|
// - run build.sh
|
||||||
|
// - swap ssh role + restart model-worker
|
||||||
|
// The build.sh runs on the HOST (or inside the ssh container). We try to
|
||||||
|
// exec it via the ssh-main container.
|
||||||
|
const sshRole = process.env.SSH_ROLE || "main";
|
||||||
|
const targetSsh = sshRole === "main" ? "ssh-companion" : "ssh";
|
||||||
|
|
||||||
|
// Build images
|
||||||
|
try {
|
||||||
|
const { stdout, stderr } = await execAsync(
|
||||||
|
`sh ${PROJECT_DIR}/build.sh`,
|
||||||
|
{
|
||||||
|
cwd: PROJECT_DIR,
|
||||||
|
env: composeEnv(),
|
||||||
|
maxBuffer: 32 * 1024 * 1024,
|
||||||
|
timeout: 600000,
|
||||||
|
}
|
||||||
|
);
|
||||||
|
const buildLog = String(stdout) + String(stderr);
|
||||||
|
|
||||||
|
// Now restart target ssh + model-worker + dashboard
|
||||||
|
const res = await runCompose(
|
||||||
|
["--profile", "wake", "up", "-d", "--force-recreate", targetSsh, "model-worker", "dashboard"],
|
||||||
|
{}
|
||||||
|
);
|
||||||
|
return {
|
||||||
|
ok: res.code === 0,
|
||||||
|
message: res.code === 0
|
||||||
|
? `Update complete: rebuilt + restarted ${targetSsh} + model-worker + dashboard`
|
||||||
|
: "Build OK, restart failed",
|
||||||
|
logs: buildLog + "\n---\n" + res.stdout + res.stderr,
|
||||||
|
};
|
||||||
|
} catch (err) {
|
||||||
|
return {
|
||||||
|
ok: false,
|
||||||
|
message: "Build failed",
|
||||||
|
logs: (err as Error).message,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// ---------------------------------------------------------------------------
|
||||||
|
// Model upload (.gguf)
|
||||||
|
// ---------------------------------------------------------------------------
|
||||||
|
|
||||||
|
export async function saveUploadedModel(
|
||||||
|
filename: string,
|
||||||
|
data: Buffer
|
||||||
|
): Promise<{ ok: boolean; path: string; error?: string }> {
|
||||||
|
// Sanitize filename — only allow .gguf extension, no path traversal
|
||||||
|
const safe = path.basename(filename).replace(/[^\w.\-]/g, "_");
|
||||||
|
if (!safe.toLowerCase().endsWith(".gguf")) {
|
||||||
|
return { ok: false, path: "", error: "Only .gguf files are allowed" };
|
||||||
|
}
|
||||||
|
const full = path.join(LLAMA_MODELS_DIR, safe);
|
||||||
|
await fs.writeFile(full, data);
|
||||||
|
return { ok: true, path: full };
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function deleteModel(
|
||||||
|
filename: string
|
||||||
|
): Promise<{ ok: boolean; error?: string }> {
|
||||||
|
const safe = path.basename(filename).replace(/[^\w.\-]/g, "_");
|
||||||
|
if (!safe.toLowerCase().endsWith(".gguf")) {
|
||||||
|
return { ok: false, error: "Only .gguf files are allowed" };
|
||||||
|
}
|
||||||
|
const full = path.join(LLAMA_MODELS_DIR, safe);
|
||||||
|
try {
|
||||||
|
await fs.unlink(full);
|
||||||
|
return { ok: true };
|
||||||
|
} catch (err) {
|
||||||
|
return { ok: false, error: (err as Error).message };
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -33,6 +33,9 @@ Usage:
|
|||||||
gpuctl stop <service>
|
gpuctl stop <service>
|
||||||
gpuctl restart <service>
|
gpuctl restart <service>
|
||||||
gpuctl logs <service>
|
gpuctl logs <service>
|
||||||
|
|
||||||
|
Services: llama, comfy, model-worker, webdav, dashboard,
|
||||||
|
ssh-main, ssh-companion, gpu-test
|
||||||
EOF
|
EOF
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -32,15 +32,17 @@ update_ssh() {
|
|||||||
echo "Rebuilding images..."
|
echo "Rebuilding images..."
|
||||||
sh "$PROJECT_DIR/build.sh"
|
sh "$PROJECT_DIR/build.sh"
|
||||||
|
|
||||||
echo "Restarting: $TARGET_SSH_SERVICE + model-worker"
|
echo "Restarting: $TARGET_SSH_SERVICE + model-worker + dashboard"
|
||||||
|
|
||||||
HOST_PROJECT_PATH="$HOST_PROJECT_PATH" \
|
HOST_PROJECT_PATH="$HOST_PROJECT_PATH" \
|
||||||
docker compose \
|
docker compose \
|
||||||
-f "$COMPOSE_FILE" \
|
-f "$COMPOSE_FILE" \
|
||||||
|
--profile wake \
|
||||||
up -d \
|
up -d \
|
||||||
--force-recreate \
|
--force-recreate \
|
||||||
"$TARGET_SSH_SERVICE" \
|
"$TARGET_SSH_SERVICE" \
|
||||||
model-worker
|
model-worker \
|
||||||
|
dashboard
|
||||||
}
|
}
|
||||||
|
|
||||||
stop_service() {
|
stop_service() {
|
||||||
@@ -113,7 +115,7 @@ sleep_mode() {
|
|||||||
echo "Entering sleep mode for instance: $NODE_INSTANCE"
|
echo "Entering sleep mode for instance: $NODE_INSTANCE"
|
||||||
echo "Keeping: tailscale + $KEEP_SSH_ROLE"
|
echo "Keeping: tailscale + $KEEP_SSH_ROLE"
|
||||||
|
|
||||||
for ROLE in llama comfyui gpu-test model-worker webdav; do
|
for ROLE in llama comfyui gpu-test model-worker webdav dashboard; do
|
||||||
CTR=$(get_service_container "$ROLE" 2>/dev/null) || true
|
CTR=$(get_service_container "$ROLE" 2>/dev/null) || true
|
||||||
[ -n "$CTR" ] && docker rm -f "$CTR" 2>/dev/null || true
|
[ -n "$CTR" ] && docker rm -f "$CTR" 2>/dev/null || true
|
||||||
done
|
done
|
||||||
@@ -149,15 +151,17 @@ wake_mode() {
|
|||||||
echo "Entering wake mode for instance: $NODE_INSTANCE"
|
echo "Entering wake mode for instance: $NODE_INSTANCE"
|
||||||
echo "Current SSH role: $SSH_ROLE"
|
echo "Current SSH role: $SSH_ROLE"
|
||||||
echo "Host project: $HOST_PROJECT_PATH"
|
echo "Host project: $HOST_PROJECT_PATH"
|
||||||
echo "Starting: $TARGET_SSH_SERVICE + model-worker + webdav"
|
echo "Starting: $TARGET_SSH_SERVICE + model-worker + webdav + dashboard"
|
||||||
|
|
||||||
HOST_PROJECT_PATH="$HOST_PROJECT_PATH" \
|
HOST_PROJECT_PATH="$HOST_PROJECT_PATH" \
|
||||||
docker compose \
|
docker compose \
|
||||||
-f "$COMPOSE_FILE" \
|
-f "$COMPOSE_FILE" \
|
||||||
|
--profile wake \
|
||||||
up -d \
|
up -d \
|
||||||
"$TARGET_SSH_SERVICE" \
|
"$TARGET_SSH_SERVICE" \
|
||||||
model-worker \
|
model-worker \
|
||||||
webdav
|
webdav \
|
||||||
|
dashboard
|
||||||
|
|
||||||
echo
|
echo
|
||||||
echo "Containers:"
|
echo "Containers:"
|
||||||
|
|||||||
Reference in New Issue
Block a user