From 61a62e658a40e32c4abfa01bf4f307bb8d364ea6 Mon Sep 17 00:00:00 2001 From: Operator Date: Sat, 17 Oct 2026 10:40:52 +0000 Subject: [PATCH] win --- .env.example | 4 +- .gitignore | 88 +++++----- START_GPU_NODE.bat | 56 +++--- comfyui/Dockerfile | 18 +- comfyui/entrypoint.sh | 150 ++++++++--------- compose.yaml | 308 ++++++++++++++++++++------------- gpu/Dockerfile | 4 +- ssh/Dockerfile | 84 +++++---- ssh/entrypoint.sh | 97 +++++++++-- ssh/gpuctl | 384 +++++++++++++++--------------------------- 10 files changed, 637 insertions(+), 556 deletions(-) diff --git a/.env.example b/.env.example index f53b772..ebb91fe 100644 --- a/.env.example +++ b/.env.example @@ -1,3 +1,3 @@ -TAILSCALE_HOSTNAME=gpu-node -TS_AUTHKEY= +TAILSCALE_HOSTNAME=gpu-node +TS_AUTHKEY= LLAMA_MODELS_PATH=./gpu/llama_models \ No newline at end of file diff --git a/.gitignore b/.gitignore index 75e339c..a1aec1f 100644 --- a/.gitignore +++ b/.gitignore @@ -1,44 +1,44 @@ -# SSH -ssh/authorized_keys - -# Tailscale -tailscale/state/ -tailscale/config/ - -# GPU models / generated data -gpu/llama_models/* -!gpu/llama_models/.gitkeep - -gpu/comfy/models/* -!gpu/comfy/models/.gitkeep - -gpu/comfy/input/* -!gpu/comfy/input/.gitkeep - -gpu/comfy/output/* -!gpu/comfy/output/.gitkeep - -gpu/comfy/custom_nodes/* -!gpu/comfy/custom_nodes/.gitkeep - -gpu/comfy/user/* -!gpu/comfy/user/.gitkeep - -comfyui/run/ -!comfyui/run/.gitkeep - - -# Environment / secrets -.env -*.env - -# Python -__pycache__/ -*.py[cod] -.venv/ - -# OS / IDE -.DS_Store -Thumbs.db -.idea/ -.vscode/ +# SSH +ssh/authorized_keys + +# Tailscale +tailscale/state/ +tailscale/config/ + +# GPU models / generated data +gpu/llama_models/* +!gpu/llama_models/.gitkeep + +gpu/comfy/models/* +!gpu/comfy/models/.gitkeep + +gpu/comfy/input/* +!gpu/comfy/input/.gitkeep + +gpu/comfy/output/* +!gpu/comfy/output/.gitkeep + +gpu/comfy/custom_nodes/* +!gpu/comfy/custom_nodes/.gitkeep + +gpu/comfy/user/* +!gpu/comfy/user/.gitkeep + +comfyui/run/ +!comfyui/run/.gitkeep + + +# Environment / secrets +.env +*.env + +# Python +__pycache__/ +*.py[cod] +.venv/ + +# OS / IDE +.DS_Store +Thumbs.db +.idea/ +.vscode/ diff --git a/START_GPU_NODE.bat b/START_GPU_NODE.bat index de89675..4e5d597 100644 --- a/START_GPU_NODE.bat +++ b/START_GPU_NODE.bat @@ -1,25 +1,33 @@ -@echo off -cd /d "%~dp0" - -echo ======================================== -echo SALEM AI GPU NODE -echo ======================================== -echo. - -echo Starting Docker services... -docker compose up -d - -if errorlevel 1 ( - echo. - echo ERROR: Failed to start GPU node. - pause - exit /b 1 -) - -echo. -echo GPU node started successfully. -echo. -docker ps --filter "name=gpu-node-" - -echo. +@echo off +setlocal enabledelayedexpansion + +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" + +echo ======================================== +echo SALEM AI GPU NODE (WSL) +echo ======================================== +echo. +echo Windows path: %WIN_DIR% +echo WSL path: %WSL_DIR% +echo. + +echo Starting Docker services via WSL... +wsl bash -c "cd '%WSL_DIR%' && docker compose up --build -d" + +if errorlevel 1 ( + echo. + echo ERROR: Failed to start GPU node in WSL. + pause + exit /b 1 +) + +echo. +echo GPU node started successfully. +echo. +wsl bash -c "docker ps --filter 'name=gpu-node-'" + +echo. pause \ No newline at end of file diff --git a/comfyui/Dockerfile b/comfyui/Dockerfile index 88d9dcd..b802720 100644 --- a/comfyui/Dockerfile +++ b/comfyui/Dockerfile @@ -1,10 +1,10 @@ -FROM ghcr.io/lecode-official/comfyui-docker:latest - -RUN cd /opt/comfyui-manager \ - && /opt/conda/bin/python -m pip install --no-cache-dir . - -COPY entrypoint.sh /entrypoint.sh - -RUN chmod +x /entrypoint.sh - +FROM ghcr.io/lecode-official/comfyui-docker:latest + +RUN cd /opt/comfyui-manager \ + && /opt/conda/bin/python -m pip install --no-cache-dir . + +COPY entrypoint.sh /entrypoint.sh + +RUN chmod +x /entrypoint.sh + ENTRYPOINT ["/entrypoint.sh"] \ No newline at end of file diff --git a/comfyui/entrypoint.sh b/comfyui/entrypoint.sh index 17853ee..ac89436 100644 --- a/comfyui/entrypoint.sh +++ b/comfyui/entrypoint.sh @@ -1,76 +1,76 @@ -#!/bin/bash - -echo "Creating directories for models..." -MODEL_DIRECTORIES=( - "checkpoints" - "clip" - "clip_vision" - "configs" - "controlnet" - "diffusers" - "diffusion_models" - "embeddings" - "gligen" - "hypernetworks" - "loras" - "photomaker" - "style_models" - "text_encoders" - "unet" - "upscale_models" - "vae" - "vae_approx" -) - -for MODEL_DIRECTORY in ${MODEL_DIRECTORIES[@]}; -do - mkdir -p /opt/comfyui/models/$MODEL_DIRECTORY -done - -echo "Creating symlink for ComfyUI Manager..." -rm --force /opt/comfyui/custom_nodes/ComfyUI-Manager -ln -s \ - /opt/comfyui-manager \ - /opt/comfyui/custom_nodes/ComfyUI-Manager - -echo "Installing requirements for custom nodes..." -for CUSTOM_NODE_DIRECTORY in /opt/comfyui/custom_nodes/*; -do - if [ "$CUSTOM_NODE_DIRECTORY" != "/opt/comfyui/custom_nodes/ComfyUI-Manager" ]; - then - if [ -f "$CUSTOM_NODE_DIRECTORY/requirements.txt" ]; - then - CUSTOM_NODE_NAME=${CUSTOM_NODE_DIRECTORY##*/} - CUSTOM_NODE_NAME=${CUSTOM_NODE_NAME//[-_]/ } - echo "Installing requirements for $CUSTOM_NODE_NAME..." - pip install --requirement "$CUSTOM_NODE_DIRECTORY/requirements.txt" - fi - fi -done - -if [ -z "$USER_ID" ] || [ -z "$GROUP_ID" ]; -then - echo "Running container as $USER..." - exec /opt/conda/bin/python main.py \ - --port 8188 \ - --listen 0.0.0.0 \ - --disable-auto-launch \ - --enable-manager \ - "$@" -else - echo "Creating non-root user..." - getent group $GROUP_ID > /dev/null 2>&1 || groupadd --gid $GROUP_ID comfyui-user - id -u $USER_ID > /dev/null 2>&1 || useradd --uid $USER_ID --gid $GROUP_ID --create-home comfyui-user - chown --recursive $USER_ID:$GROUP_ID /opt/comfyui - chown --recursive $USER_ID:$GROUP_ID /opt/comfyui-manager - export PATH=$PATH:/home/comfyui-user/.local/bin - - echo "Running as comfyui-user..." - sudo --set-home --preserve-env=PATH --user \#$USER_ID \ - /opt/conda/bin/python main.py \ - --port 8188 \ - --listen 0.0.0.0 \ - --disable-auto-launch \ - --enable-manager \ - "$@" +#!/bin/bash + +echo "Creating directories for models..." +MODEL_DIRECTORIES=( + "checkpoints" + "clip" + "clip_vision" + "configs" + "controlnet" + "diffusers" + "diffusion_models" + "embeddings" + "gligen" + "hypernetworks" + "loras" + "photomaker" + "style_models" + "text_encoders" + "unet" + "upscale_models" + "vae" + "vae_approx" +) + +for MODEL_DIRECTORY in ${MODEL_DIRECTORIES[@]}; +do + mkdir -p /opt/comfyui/models/$MODEL_DIRECTORY +done + +echo "Creating symlink for ComfyUI Manager..." +rm --force /opt/comfyui/custom_nodes/ComfyUI-Manager +ln -s \ + /opt/comfyui-manager \ + /opt/comfyui/custom_nodes/ComfyUI-Manager + +echo "Installing requirements for custom nodes..." +for CUSTOM_NODE_DIRECTORY in /opt/comfyui/custom_nodes/*; +do + if [ "$CUSTOM_NODE_DIRECTORY" != "/opt/comfyui/custom_nodes/ComfyUI-Manager" ]; + then + if [ -f "$CUSTOM_NODE_DIRECTORY/requirements.txt" ]; + then + CUSTOM_NODE_NAME=${CUSTOM_NODE_DIRECTORY##*/} + CUSTOM_NODE_NAME=${CUSTOM_NODE_NAME//[-_]/ } + echo "Installing requirements for $CUSTOM_NODE_NAME..." + pip install --requirement "$CUSTOM_NODE_DIRECTORY/requirements.txt" + fi + fi +done + +if [ -z "$USER_ID" ] || [ -z "$GROUP_ID" ]; +then + echo "Running container as $USER..." + exec /opt/conda/bin/python main.py \ + --port 8188 \ + --listen 0.0.0.0 \ + --disable-auto-launch \ + --enable-manager \ + "$@" +else + echo "Creating non-root user..." + getent group $GROUP_ID > /dev/null 2>&1 || groupadd --gid $GROUP_ID comfyui-user + id -u $USER_ID > /dev/null 2>&1 || useradd --uid $USER_ID --gid $GROUP_ID --create-home comfyui-user + chown --recursive $USER_ID:$GROUP_ID /opt/comfyui + chown --recursive $USER_ID:$GROUP_ID /opt/comfyui-manager + export PATH=$PATH:/home/comfyui-user/.local/bin + + echo "Running as comfyui-user..." + sudo --set-home --preserve-env=PATH --user \#$USER_ID \ + /opt/conda/bin/python main.py \ + --port 8188 \ + --listen 0.0.0.0 \ + --disable-auto-launch \ + --enable-manager \ + "$@" fi \ No newline at end of file diff --git a/compose.yaml b/compose.yaml index b5b7202..7533e2f 100644 --- a/compose.yaml +++ b/compose.yaml @@ -1,115 +1,195 @@ -name: gpu-node - -services: - tailscale: - image: tailscale/tailscale:latest - container_name: gpu-node-tailscale - - hostname: ${TAILSCALE_HOSTNAME:-gpu-node} - - environment: - TS_AUTHKEY: ${TS_AUTHKEY} - TS_STATE_DIR: /var/lib/tailscale - TS_SERVE_CONFIG: /config/serve.json - - volumes: - - ./tailscale/state:/var/lib/tailscale - - ./tailscale/config:/config:ro - - networks: - - gpu-node - - restart: always - - ssh: - build: - context: ./ssh - - container_name: gpu-node-ssh - hostname: ssh-operator - - volumes: - - ./ssh/authorized_keys:/mounted-authorized-keys:ro - - /var/run/docker.sock:/var/run/docker.sock - - ./:/project:ro - - networks: - - gpu-node - - restart: always - - gpu-test: - profiles: - - test - - build: - context: ./gpu - - container_name: gpu-node-gpu-test - - gpus: all - - networks: - - gpu-node - - restart: "no" - - llama: - profiles: - - llama - - image: ghcr.io/ggml-org/llama.cpp:server-cuda - - container_name: gpu-node-llama - - gpus: all - - volumes: - - ${LLAMA_MODELS_HOST:-./gpu/llama_models}:/models - - command: > - --host 0.0.0.0 - --port 8080 - --model /models/${LLAMA_MODEL:-model.gguf} - ${LLAMA_EXTRA_ARGS:-} - - networks: - - gpu-node - - restart: "no" - - comfyui: - profiles: - - comfy - - image: mmartial/comfyui-nvidia-docker:latest - - container_name: gpu-node-comfyui - - init: true - - gpus: all - - ports: - - "8188:8188" - - volumes: - - ./comfyui/run:/comfy/mnt - - ./gpu/comfy:/basedir - - environment: - USE_UV: "true" - WANTED_UID: "1000" - WANTED_GID: "1000" - BASE_DIRECTORY: "/basedir" - SECURITY_LEVEL: "normal" - COMFY_CMDLINE_EXTRA: ${COMFY_EXTRA_ARGS:-} - - networks: - - gpu-node - - restart: "no" - -networks: - gpu-node: + +name: ${TAILSCALE_HOSTNAME:-gpu-node} + +services: + tailscale: + image: tailscale/tailscale:latest + + container_name: ${TAILSCALE_HOSTNAME:-gpu-node}-tailscale + hostname: ${TAILSCALE_HOSTNAME:-gpu-node} + + environment: + TS_AUTHKEY: ${TS_AUTHKEY} + TS_STATE_DIR: /var/lib/tailscale + TS_SERVE_CONFIG: /config/serve.json + + volumes: + - ${HOST_PROJECT_PATH:-.}/tailscale/state:/var/lib/tailscale + - ${HOST_PROJECT_PATH:-.}/tailscale/config:/config:ro + + networks: + - gpu-node + + restart: always + + + ssh: + build: + context: ./ssh + + container_name: ${TAILSCALE_HOSTNAME:-gpu-node}-ssh-main + hostname: ssh-main + + environment: + HOST_PROJECT_PATH: ${HOST_PROJECT_PATH} + SSH_ROLE: main + SSH_PORT: "22" + + volumes: + - /var/run/docker.sock:/var/run/docker.sock + - ${HOST_PROJECT_PATH:-./}:/project + + networks: + - gpu-node + + restart: always + + + ssh-companion: + profiles: + - wake + + build: + context: ./ssh + + container_name: ${TAILSCALE_HOSTNAME:-gpu-node}-ssh-companion + hostname: ssh-companion + + environment: + HOST_PROJECT_PATH: ${HOST_PROJECT_PATH} + SSH_ROLE: companion + SSH_PORT: "2222" + + volumes: + - /var/run/docker.sock:/var/run/docker.sock + - ${HOST_PROJECT_PATH:-./}:/project + + networks: + - gpu-node + + restart: always + + + webdav: + profiles: + - wake + + image: rclone/rclone:latest + + container_name: ${TAILSCALE_HOSTNAME:-gpu-node}-webdav + hostname: webdav + + command: + - serve + - webdav + - /data + - --addr + - :8080 + - --user + - ${WEBDAV_USER:-operator} + - --pass + - ${WEBDAV_PASS} + + volumes: + - ${HOST_PROJECT_PATH:-./}:/data + + networks: + - gpu-node + + restart: always + + + gpu-test: + profiles: + - test + + build: + context: ./gpu + + container_name: ${TAILSCALE_HOSTNAME:-gpu-node}-gpu-test + + gpus: all + + networks: + - gpu-node + + restart: "no" + + + model-worker: + profiles: + - wake + + build: + context: ./model-worker + + container_name: ${TAILSCALE_HOSTNAME:-gpu-node}-model-worker + + volumes: + - ${HOST_PROJECT_PATH:-./}/gpu/comfy/models:/models + - ${HOST_PROJECT_PATH:-./}/gpu/model-worker:/state + + networks: + - gpu-node + + restart: always + + + llama: + profiles: + - llama + + image: ghcr.io/ggml-org/llama.cpp:server-cuda + + container_name: ${TAILSCALE_HOSTNAME:-gpu-node}-llama + + gpus: all + + volumes: + - ${LLAMA_MODELS_HOST:-./gpu/llama_models}:/models + + command: > + --host 0.0.0.0 + --port 8080 + --model /models/${LLAMA_MODEL:-model.gguf} + ${LLAMA_EXTRA_ARGS:-} + + networks: + - gpu-node + + restart: "no" + + + comfyui: + profiles: + - comfy + + image: mmartial/comfyui-nvidia-docker:latest + + container_name: ${TAILSCALE_HOSTNAME:-gpu-node}-comfyui + + init: true + + gpus: all + + volumes: + - ${COMFY_RUN_HOST:-./comfyui/run}:/comfy/mnt + - ${COMFY_BASE_HOST:-./gpu/comfy}:/basedir + + environment: + USE_UV: "true" + WANTED_UID: "1000" + WANTED_GID: "1000" + BASE_DIRECTORY: "/basedir" + SECURITY_LEVEL: "normal" + COMFY_CMDLINE_EXTRA: ${COMFY_EXTRA_ARGS:-} + + networks: + - gpu-node + + restart: "no" + + +networks: + gpu-node: name: gpu-node \ No newline at end of file diff --git a/gpu/Dockerfile b/gpu/Dockerfile index 2b85d4a..ba981d9 100644 --- a/gpu/Dockerfile +++ b/gpu/Dockerfile @@ -1,3 +1,3 @@ -FROM nvidia/cuda:12.8.1-base-ubuntu24.04 - +FROM nvidia/cuda:12.8.1-base-ubuntu24.04 + CMD ["nvidia-smi"] \ No newline at end of file diff --git a/ssh/Dockerfile b/ssh/Dockerfile index e3c4200..7d68dea 100644 --- a/ssh/Dockerfile +++ b/ssh/Dockerfile @@ -1,31 +1,55 @@ -FROM alpine:3.22 - -RUN apk add --no-cache \ - openssh-server \ - docker-cli \ - docker-cli-compose \ - && addgroup -g 1001 docker-host \ - && adduser -D -s /bin/sh operator \ - && adduser operator docker-host \ - && passwd -d operator \ - && mkdir -p /home/operator/.ssh \ - && ssh-keygen -A - -RUN printf '%s\n' \ - 'PasswordAuthentication no' \ - 'KbdInteractiveAuthentication no' \ - 'PubkeyAuthentication yes' \ - 'PermitRootLogin no' \ - >> /etc/ssh/sshd_config - -COPY entrypoint.sh /entrypoint.sh -COPY gpuctl /usr/local/bin/gpuctl - -RUN sed -i 's/\r$//' /usr/local/bin/gpuctl \ - && chmod +x /entrypoint.sh /usr/local/bin/gpuctl - -RUN chmod +x /entrypoint.sh /usr/local/bin/gpuctl - -EXPOSE 22 - +FROM alpine:3.22 + +RUN apk add --no-cache \ + openssh-server \ + docker-cli \ + docker-cli-compose \ + git \ + curl \ + wget \ + bash \ + jq \ + vim \ + less \ + htop \ + nano \ + iproute2 \ + bind-tools \ + tcpdump \ + procps \ + util-linux \ + tree \ + file \ + ca-certificates \ + tzdata \ + && addgroup -g 1001 docker-host \ + && adduser -D -s /bin/bash operator \ + && adduser operator docker-host \ + && passwd -d operator \ + && mkdir -p /home/operator/.ssh \ + && ssh-keygen -A + +RUN printf '%s\n' \ + 'PasswordAuthentication no' \ + 'KbdInteractiveAuthentication no' \ + 'PubkeyAuthentication yes' \ + 'PermitRootLogin no' \ + >> /etc/ssh/sshd_config + +COPY entrypoint.sh /entrypoint.sh + +COPY gpuctl /usr/local/bin/gpuctl +COPY scripts/ /usr/local/lib/scripts/ + +RUN sed -i 's/\r$//' \ + /entrypoint.sh \ + /usr/local/bin/gpuctl \ + /usr/local/lib/scripts/*.sh \ + && chmod +x \ + /entrypoint.sh \ + /usr/local/bin/gpuctl \ + /usr/local/lib/scripts/*.sh + +EXPOSE 22 + ENTRYPOINT ["/entrypoint.sh"] \ No newline at end of file diff --git a/ssh/entrypoint.sh b/ssh/entrypoint.sh index 67b7306..e6f2c5f 100644 --- a/ssh/entrypoint.sh +++ b/ssh/entrypoint.sh @@ -1,10 +1,87 @@ -#!/bin/sh -set -e - -cp /mounted-authorized-keys /home/operator/.ssh/authorized_keys - -chown -R operator:operator /home/operator/.ssh -chmod 700 /home/operator/.ssh -chmod 600 /home/operator/.ssh/authorized_keys - -exec /usr/sbin/sshd -D -e \ No newline at end of file +#!/bin/sh + +set -eu + + + +# ------------------------------------------------------------ +# Configuration +# ------------------------------------------------------------ + +HOST_PROJECT_PATH="${HOST_PROJECT_PATH:-}" +SSH_ROLE="${SSH_ROLE:-}" +SSH_PORT="${SSH_PORT:-22}" + + +if [ -z "$HOST_PROJECT_PATH" ]; then + echo "ERROR: HOST_PROJECT_PATH is not set." >&2 + exit 1 +fi + + +if [ -z "$SSH_ROLE" ]; then + echo "ERROR: SSH_ROLE is not set." >&2 + exit 1 +fi + + +case "$SSH_ROLE" in + + main) + EXPECTED_PORT="22" + ;; + + companion) + EXPECTED_PORT="2222" + ;; + + *) + echo "ERROR: unknown SSH_ROLE: $SSH_ROLE" >&2 + echo "Expected: main or companion" >&2 + exit 1 + ;; + +esac + +# ------------------------------------------------------------ +# SSH authorized keys +# ------------------------------------------------------------ + +cp /project/ssh/authorized_keys /home/operator/.ssh/authorized_keys + +chown -R operator:operator /home/operator/.ssh +chmod 700 /home/operator/.ssh +chmod 600 /home/operator/.ssh/authorized_keys + +# ------------------------------------------------------------ +# Interactive shell environment +# ------------------------------------------------------------ + +cat > /etc/profile.d/gpu-node.sh </dev/null || true - ;; - - comfy) - docker stop gpu-node-comfyui 2>/dev/null || true - ;; - - tailscale) - docker stop gpu-node-tailscale 2>/dev/null || true - ;; - - ssh) - docker stop gpu-node-ssh 2>/dev/null || true - ;; - - *) - echo "Unknown service: $SERVICE" - exit 1 - ;; - esac -} - - -restart_service() { - SERVICE="$1" - - case "$SERVICE" in - llama) - docker restart gpu-node-llama - ;; - - comfy) - docker restart gpu-node-comfyui - ;; - - tailscale) - docker restart gpu-node-tailscale - ;; - - ssh) - docker restart gpu-node-ssh - ;; - - *) - echo "Unknown service: $SERVICE" - exit 1 - ;; - esac -} - - -logs_service() { - SERVICE="$1" - - case "$SERVICE" in - llama) - docker logs -f gpu-node-llama - ;; - - comfy) - docker logs -f gpu-node-comfyui - ;; - - tailscale) - docker logs -f gpu-node-tailscale - ;; - - ssh) - docker logs -f gpu-node-ssh - ;; - - *) - echo "Unknown service: $SERVICE" - exit 1 - ;; - esac -} - - -case "${1:-}" in - - status) - show_status - ;; - - start) - case "${2:-}" in - - llama) - shift 2 - start_llama "$@" - ;; - - comfy) - shift 2 - start_comfy "$@" - ;; - - *) - echo "Usage:" - echo " gpuctl start llama [model.gguf] [extra args...]" - echo " gpuctl start comfy [extra args...]" - exit 1 - ;; - esac - ;; - - stop) - if [ -z "${2:-}" ]; then - echo "Usage: gpuctl stop " - exit 1 - fi - - stop_service "$2" - ;; - - restart) - if [ -z "${2:-}" ]; then - echo "Usage: gpuctl restart " - exit 1 - fi - - restart_service "$2" - ;; - - logs) - if [ -z "${2:-}" ]; then - echo "Usage: gpuctl logs " - exit 1 - fi - - logs_service "$2" - ;; - - *) - echo "GPU node controller" - echo - echo "Usage:" - echo " gpuctl status" - echo " gpuctl start llama [model.gguf] [extra args...]" - echo " gpuctl start comfy [extra args...]" - echo " gpuctl stop " - echo " gpuctl restart " - echo " gpuctl logs " - exit 1 - ;; - + +#!/bin/sh + +set -eu + +GPuctl_LIB="/usr/local/lib/scripts" + +. "$GPuctl_LIB/common.sh" +. "$GPuctl_LIB/status.sh" +. "$GPuctl_LIB/gpu.sh" +. "$GPuctl_LIB/llama.sh" +. "$GPuctl_LIB/comfy.sh" + + +show_usage() { + cat <<'EOF' +Usage: + + gpuctl status + gpuctl gpu + gpuctl update + gpuctl sleep + gpuctl wake + + gpuctl start llama [model.gguf] [extra args...] + gpuctl start comfy [extra args...] + + gpuctl comfy models list [type] + gpuctl comfy models queue + gpuctl comfy models add + gpuctl comfy models rm [type] + + gpuctl stop + gpuctl restart + gpuctl logs +EOF +} + + +case "${1:-}" in + + status) + show_status + ;; + + gpu) + show_gpu + ;; + + update) + if [ "$#" -ne 1 ]; then + echo "Usage: gpuctl update" >&2 + exit 1 + fi + + update_ssh + ;; + + sleep) + if [ "$#" -ne 1 ]; then + echo "Usage: gpuctl sleep" >&2 + exit 1 + fi + + sleep_mode + ;; + + wake) + if [ "$#" -ne 1 ]; then + echo "Usage: gpuctl wake" >&2 + exit 1 + fi + + wake_mode + ;; + + start) + case "${2:-}" in + + llama) + shift 2 + start_llama "$@" + ;; + + comfy) + shift 2 + start_comfy "$@" + ;; + + *) + show_usage + exit 1 + ;; + esac + ;; + + comfy) + shift + comfy_command "$@" + ;; + + llama) + shift + llama_command "$@" + ;; + + stop) + if [ "$#" -ne 2 ]; then + echo "Usage: gpuctl stop " >&2 + exit 1 + fi + + stop_service "$2" + ;; + + restart) + if [ "$#" -ne 2 ]; then + echo "Usage: gpuctl restart " >&2 + exit 1 + fi + + restart_service "$2" + ;; + + logs) + if [ "$#" -ne 2 ]; then + echo "Usage: gpuctl logs " >&2 + exit 1 + fi + + logs_service "$2" + ;; + + *) + show_usage + exit 1 + ;; + esac \ No newline at end of file