COMFY_DIR alone manages ComfyUI: derive the launch command from the standard venv layout
This commit is contained in:
@@ -15,6 +15,7 @@ import (
|
||||
"os"
|
||||
"os/signal"
|
||||
"path/filepath"
|
||||
"runtime"
|
||||
"strings"
|
||||
"syscall"
|
||||
"time"
|
||||
@@ -434,7 +435,26 @@ func orDisabled(url string) string {
|
||||
return url
|
||||
}
|
||||
|
||||
// managedComfyCommand resolves how ComfyUI is launched when it is managed:
|
||||
// COMFY_CMD verbatim, or the standard venv layout under COMFY_DIR. Empty
|
||||
// when neither is set (unmanaged).
|
||||
func managedComfyCommand(cfg config.Config) string {
|
||||
if cfg.ComfyCmd != "" {
|
||||
return cfg.ComfyCmd
|
||||
}
|
||||
if cfg.ComfyDir != "" {
|
||||
return supervise.DefaultComfyCommand(runtime.GOOS, cfg.ComfyDir, cfg.ComfyURL)
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
func run(ctx context.Context, cfg config.Config, log *slog.Logger, logOut io.Writer, isService bool) error {
|
||||
// ComfyUI can run as a managed child — COMFY_CMD verbatim, or the
|
||||
// standard venv layout derived from COMFY_DIR alone: started on demand
|
||||
// by the proxy, stopped after COMFY_IDLE_TIMEOUT idle (and on shutdown)
|
||||
// so its VRAM is freed.
|
||||
comfyCmdLine := managedComfyCommand(cfg)
|
||||
|
||||
// The startup line carries the version and every setting and is emitted
|
||||
// at WARN so it is visible even with the default (quiet) log level.
|
||||
log.Log(ctx, slog.LevelWarn, "starting gpu-turnstile",
|
||||
@@ -460,7 +480,7 @@ func run(ctx context.Context, cfg config.Config, log *slog.Logger, logOut io.Wri
|
||||
"backoff_max", cfg.BackoffMax,
|
||||
"prompt_capture_limit", cfg.PromptCaptureLimit,
|
||||
"warm_model", cfg.WarmModel,
|
||||
"comfy_cmd", cfg.ComfyCmd,
|
||||
"comfy_cmd", orDisabled(comfyCmdLine),
|
||||
"comfy_dir", cfg.ComfyDir,
|
||||
"comfy_idle_timeout", cfg.ComfyIdleTimeout,
|
||||
"comfy_start_timeout", cfg.ComfyStartTimeout,
|
||||
@@ -494,13 +514,20 @@ func run(ctx context.Context, cfg config.Config, log *slog.Logger, logOut io.Wri
|
||||
}
|
||||
}
|
||||
|
||||
// With COMFY_CMD set, ComfyUI runs as a managed child: started on
|
||||
// demand by the proxy, stopped after COMFY_IDLE_TIMEOUT idle (and on
|
||||
// shutdown) so its VRAM is freed.
|
||||
var comfySup *supervise.Process
|
||||
if cfg.ComfyCmd != "" {
|
||||
if comfyCmdLine != "" {
|
||||
if cfg.ComfyCmd == "" {
|
||||
// Derived from COMFY_DIR: flag a wrong-looking layout early,
|
||||
// while the operator is still watching the startup log.
|
||||
python, script := supervise.ComfyLayout(runtime.GOOS, cfg.ComfyDir)
|
||||
for _, p := range []string{python, script} {
|
||||
if _, err := os.Stat(p); err != nil {
|
||||
log.Warn("COMFY_DIR: file not found; ComfyUI requests will fail until it exists", "path", p)
|
||||
}
|
||||
}
|
||||
}
|
||||
var err error
|
||||
comfySup, err = supervise.New("comfy", cfg.ComfyCmd, cfg.ComfyDir, comfyClient.Probe, cfg.ComfyStartTimeout, log)
|
||||
comfySup, err = supervise.New("comfy", comfyCmdLine, cfg.ComfyDir, comfyClient.Probe, cfg.ComfyStartTimeout, log)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user