This commit is contained in:
Mikan
2026-10-16 12:36:58 +04:00
parent 486a718eab
commit fbff0edf77
6 changed files with 112 additions and 180 deletions

View File

@@ -17,7 +17,6 @@ start_comfy() {
fi
HOST_PROJECT_PATH="$HOST_PROJECT_PATH" \
PROJECT_HOST_DIR="$HOST_PROJECT_PATH" \
COMFY_BASE_HOST="$HOST_PROJECT_PATH/gpu/comfy" \
COMFY_RUN_HOST="$HOST_PROJECT_PATH/comfyui/run" \
COMFY_EXTRA_ARGS="$EXTRA_ARGS" \
@@ -31,29 +30,32 @@ start_comfy() {
echo
docker ps \
--filter "name=gpu-node-comfyui" \
--filter "label=node.role=comfyui" \
--filter "label=node.instance=${NODE_INSTANCE}" \
--format 'table {{.Names}}\t{{.Status}}\t{{.Ports}}'
}
model_worker_exec() {
MW_CONTAINER=$(get_service_container "model-worker") || {
echo "ERROR: model-worker container not found for instance '${NODE_INSTANCE}'" >&2
return 1
}
docker exec \
gpu-node-model-worker \
"$MW_CONTAINER" \
python3 \
/app/worker.py \
"$@"
}
list_comfy_models() {
model_worker_exec list "$@"
}
queue_comfy_models() {
model_worker_exec queue "$@"
}
add_comfy_model() {
if [ "$#" -ne 2 ]; then
echo "Usage: gpuctl comfy models add <URL> <type>" >&2
@@ -63,7 +65,6 @@ add_comfy_model() {
model_worker_exec add "$1" "$2"
}
remove_comfy_model() {
if [ "$#" -lt 1 ] || [ "$#" -gt 2 ]; then
echo "Usage: gpuctl comfy models rm <filename> [type]" >&2
@@ -73,42 +74,32 @@ remove_comfy_model() {
model_worker_exec rm "$@"
}
comfy_models_command() {
case "${1:-}" in
list)
shift
if [ "$#" -gt 1 ]; then
echo "Usage: gpuctl comfy models list [type]" >&2
return 1
fi
list_comfy_models "$@"
;;
queue)
shift
if [ "$#" -ne 0 ]; then
echo "Usage: gpuctl comfy models queue" >&2
return 1
fi
queue_comfy_models
;;
add)
shift
add_comfy_model "$@"
;;
rm)
shift
remove_comfy_model "$@"
;;
*)
echo "Usage:"
echo " gpuctl comfy models list [type]"
@@ -120,15 +111,12 @@ comfy_models_command() {
esac
}
comfy_command() {
case "${1:-}" in
models)
shift
comfy_models_command "$@"
;;
*)
echo "Usage:"
echo " gpuctl comfy models list [type]"
@@ -138,4 +126,4 @@ comfy_command() {
return 1
;;
esac
}
}

View File

@@ -17,9 +17,38 @@ require_ssh_role() {
fi
}
require_node_instance() {
if [ -z "${NODE_INSTANCE:-}" ]; then
echo "ERROR: NODE_INSTANCE is not set." >&2
exit 1
fi
}
require_project_dir() {
if [ ! -d "$PROJECT_DIR" ]; then
echo "ERROR: Project directory not found: $PROJECT_DIR" >&2
exit 1
fi
}
}
get_service_container() {
ROLE="$1"
case "$ROLE" in
ssh|ssh-main) ROLE="ssh-main" ;;
comfy) ROLE="comfyui" ;;
esac
CONTAINER=$(docker ps -a \
--filter "label=node.role=$ROLE" \
--filter "label=node.instance=${NODE_INSTANCE}" \
--format '{{.Names}}' \
| head -n 1)
if [ -z "$CONTAINER" ]; then
return 1
fi
echo "$CONTAINER"
}

View File

@@ -21,7 +21,6 @@ start_llama() {
fi
HOST_PROJECT_PATH="$HOST_PROJECT_PATH" \
PROJECT_HOST_DIR="$HOST_PROJECT_PATH" \
LLAMA_MODELS_HOST="$HOST_PROJECT_PATH/gpu/llama_models" \
LLAMA_MODEL="$MODEL" \
LLAMA_EXTRA_ARGS="$EXTRA_ARGS" \
@@ -35,11 +34,11 @@ start_llama() {
echo
docker ps \
--filter "name=gpu-node-llama" \
--filter "label=node.role=llama" \
--filter "label=node.instance=${NODE_INSTANCE}" \
--format 'table {{.Names}}\t{{.Status}}\t{{.Ports}}'
}
llama_command() {
case "${1:-}" in
*)
@@ -47,4 +46,4 @@ llama_command() {
echo " gpuctl llama"
;;
esac
}
}

View File

@@ -1,21 +1,17 @@
#!/bin/sh
show_status() {
docker ps \
--filter "name=gpu-node-" \
--filter "label=node.instance=${NODE_INSTANCE}" \
--format 'table {{.Names}}\t{{.Status}}\t{{.Ports}}'
}
update_ssh() {
cd "$PROJECT_DIR"
require_host_project_path
require_ssh_role
# SSH_KEYS_HOST="$HOST_PROJECT_PATH/ssh/authorized_keys"
case "$SSH_ROLE" in
main)
TARGET_SSH_SERVICE="ssh-companion"
@@ -30,11 +26,11 @@ update_ssh() {
esac
echo "Current SSH role: $SSH_ROLE"
echo "Node instance: $NODE_INSTANCE"
echo "Host project: $HOST_PROJECT_PATH"
echo "Updating: $TARGET_SSH_SERVICE + model-worker"
HOST_PROJECT_PATH="$HOST_PROJECT_PATH" \
PROJECT_HOST_DIR="$HOST_PROJECT_PATH" \
docker compose \
-f "$COMPOSE_FILE" \
up -d \
@@ -44,37 +40,6 @@ update_ssh() {
model-worker
}
get_service_container() {
case "$1" in
llama)
echo "gpu-node-llama"
;;
comfy)
echo "gpu-node-comfyui"
;;
tailscale)
echo "gpu-node-tailscale"
;;
ssh|ssh-main)
echo "gpu-node-ssh-main"
;;
ssh-companion)
echo "gpu-node-ssh-companion"
;;
webdav)
echo "gpu-node-webdav"
;;
model-worker)
echo "gpu-node-model-worker"
;;
*)
return 1
;;
esac
}
stop_service() {
CONTAINER="$(get_service_container "$1")" || {
echo "Unknown service: $1" >&2
@@ -84,7 +49,6 @@ stop_service() {
docker stop "$CONTAINER" 2>/dev/null || true
}
restart_service() {
CONTAINER="$(get_service_container "$1")" || {
echo "Unknown service: $1" >&2
@@ -94,7 +58,6 @@ restart_service() {
docker restart "$CONTAINER"
}
logs_service() {
CONTAINER="$(get_service_container "$1")" || {
echo "Unknown service: $1" >&2
@@ -104,78 +67,71 @@ logs_service() {
docker logs -f "$CONTAINER"
}
container_is_running() {
[ "$(docker inspect \
--format '{{.State.Running}}' "$1" 2>/dev/null || true)" = "true" ]
}
TARGET="$1"
# Если передали роль — резолвим в имя контейнера
RESOLVED=$(get_service_container "$TARGET" 2>/dev/null) || true
if [ -n "$RESOLVED" ]; then
TARGET="$RESOLVED"
fi
[ "$(docker inspect \
--format '{{.State.Running}}' "$TARGET" 2>/dev/null || true)" = "true" ]
}
sleep_mode() {
cd "$PROJECT_DIR"
require_host_project_path
require_ssh_role
require_node_instance
MAIN_CONTAINER="gpu-node-ssh-main"
COMPANION_CONTAINER="gpu-node-ssh-companion"
# Prefer ssh-main if it is running.
if container_is_running "$MAIN_CONTAINER"; then
KEEP_SSH="ssh"
REMOVE_SSH="ssh-companion"
elif container_is_running "$COMPANION_CONTAINER"; then
KEEP_SSH="ssh-companion"
REMOVE_SSH="ssh"
MAIN_CONTAINER=$(get_service_container "ssh-main") || MAIN_CONTAINER=""
COMPANION_CONTAINER=$(get_service_container "ssh-companion") || COMPANION_CONTAINER=""
if [ -n "$MAIN_CONTAINER" ] && container_is_running "$MAIN_CONTAINER"; then
KEEP_SSH_ROLE="ssh-main"
REMOVE_SSH_ROLE="ssh-companion"
elif [ -n "$COMPANION_CONTAINER" ] && container_is_running "$COMPANION_CONTAINER"; then
KEEP_SSH_ROLE="ssh-companion"
REMOVE_SSH_ROLE="ssh-main"
else
echo "No SSH container is running. Starting ssh-main..."
echo "No SSH container running for instance '$NODE_INSTANCE'. Starting ssh-main..."
HOST_PROJECT_PATH="$HOST_PROJECT_PATH" \
PROJECT_HOST_DIR="$HOST_PROJECT_PATH" \
SSH_KEYS_HOST="$HOST_PROJECT_PATH/ssh/authorized_keys" \
docker compose \
-f "$COMPOSE_FILE" \
up -d ssh
KEEP_SSH="ssh"
REMOVE_SSH="ssh-companion"
KEEP_SSH_ROLE="ssh-main"
REMOVE_SSH_ROLE="ssh-companion"
fi
echo "Entering sleep mode."
echo "Keeping: tailscale + $KEEP_SSH"
echo "Entering sleep mode for instance: $NODE_INSTANCE"
echo "Keeping: tailscale + $KEEP_SSH_ROLE"
# Remove optional containers, including stopped ones.
docker rm -f \
gpu-node-llama \
gpu-node-comfyui \
gpu-node-gpu-test \
gpu-node-model-worker \
gpu-node-webdav \
2>/dev/null || true
# Удаляем опциональные контейнеры ТОЛЬКО своего инстанса
for ROLE in llama comfyui gpu-test model-worker webdav; do
CTR=$(get_service_container "$ROLE" 2>/dev/null) || true
[ -n "$CTR" ] && docker rm -f "$CTR" 2>/dev/null || true
done
# Remove the other SSH container.
if [ "$REMOVE_SSH" = "ssh" ]; then
docker rm -f "$MAIN_CONTAINER" 2>/dev/null || true
else
docker rm -f "$COMPANION_CONTAINER" 2>/dev/null || true
fi
# Удаляем ненужный SSH-контейнер
REMOVE_CTR=$(get_service_container "$REMOVE_SSH_ROLE" 2>/dev/null) || true
[ -n "$REMOVE_CTR" ] && docker rm -f "$REMOVE_CTR" 2>/dev/null || true
echo
echo "Sleep mode ready."
docker ps \
--filter "name=gpu-node-" \
--format 'table {{.Names}}\t{{.Status}}\t{{.Ports}}'
show_status
}
wake_mode() {
cd "$PROJECT_DIR"
require_host_project_path
require_ssh_role
require_node_instance
case "$SSH_ROLE" in
main)
@@ -190,14 +146,12 @@ wake_mode() {
;;
esac
echo "Entering wake mode."
echo "Entering wake mode for instance: $NODE_INSTANCE"
echo "Current SSH role: $SSH_ROLE"
echo "Host project: $HOST_PROJECT_PATH"
echo "Starting: $TARGET_SSH_SERVICE + model-worker + webdav"
HOST_PROJECT_PATH="$HOST_PROJECT_PATH" \
PROJECT_HOST_DIR="$HOST_PROJECT_PATH" \
SSH_KEYS_HOST="$HOST_PROJECT_PATH/ssh/authorized_keys" \
docker compose \
-f "$COMPOSE_FILE" \
up -d \
@@ -211,4 +165,4 @@ wake_mode() {
echo
show_gpu
}
}