Buckets:
| set -euo pipefail | |
| umask 027 | |
| main_dir="$(cd -- "$(dirname -- "$0")" && pwd)" | |
| system_python="${SYSTEM_PYTHON:-/usr/local/bin/python}" | |
| mode="${1:-}" | |
| login_dir=/var/lib/comfyui-login | |
| if [[ "$mode" == --help || "$mode" == -h ]]; then | |
| echo "用法:bash comfyui.sh [--setup-only | --link-models-only | ComfyUI 参数]" | |
| echo "缺少依赖时由 root 自动安装;--setup-only 仅安装依赖和初始化登录。" | |
| exit 0 | |
| fi | |
| if [[ "$EUID" -ne 0 && "$(id -un)" != comfyui ]]; then | |
| echo "请使用 sudo bash $main_dir/comfyui.sh;服务会自动降权为 comfyui。" >&2 | |
| exit 1 | |
| fi | |
| for argument in "$@"; do | |
| case "$argument" in | |
| --enable-manager*) echo "公网启动不启用 Manager;插件请在终端维护。" >&2; exit 1 ;; | |
| esac | |
| done | |
| if [[ "$EUID" -eq 0 ]]; then | |
| if ! id comfyui >/dev/null 2>&1; then | |
| useradd --system --user-group --create-home --home-dir /var/lib/comfyui --shell /usr/sbin/nologin comfyui | |
| fi | |
| for model_pair in "loras:Lora" "checkpoints:Stable-diffusion" "diffusion_models:Stable-diffusion" \ | |
| "text_encoders:sd-webui-forge-neo/models/text_encoder" "vae:sd-webui-forge-neo/models/VAE"; do | |
| model_type="${model_pair%%:*}" | |
| shared_dir="${model_pair#*:}" | |
| model_link="$main_dir/ComfyUI/models/$model_type/${shared_dir##*/}" | |
| mkdir -p -- "$main_dir/$shared_dir" "$main_dir/ComfyUI/models/$model_type" | |
| if [[ -e "$model_link" && ! -L "$model_link" ]]; then | |
| echo "模型链接位置已有文件或目录:$model_link" >&2 | |
| exit 1 | |
| fi | |
| ln -sfnT -- "$main_dir/$shared_dir" "$model_link" | |
| done | |
| fi | |
| if [[ "$mode" == --link-models-only ]]; then exit 0; fi | |
| cd -- "$main_dir/ComfyUI" | |
| unset PYTHONPATH PYTHONHOME | |
| export PYTHONNOUSERSITE=1 LC_ALL=C.UTF-8 | |
| needs_setup=0 | |
| if ! "$system_python" -I - <<'PY_DEPS' | |
| from importlib.metadata import PackageNotFoundError, version | |
| from pathlib import Path | |
| from packaging.requirements import Requirement | |
| missing = [] | |
| files = [Path('requirements.txt'), Path('custom_nodes/ComfyUI-Login/requirements.txt'), | |
| Path('custom_nodes/seedvr2_videoupscaler/requirements.txt')] | |
| for file in files: | |
| if not file.is_file(): | |
| continue | |
| for line in file.read_text().splitlines(): | |
| line = line.split('#', 1)[0].strip() | |
| if not line: | |
| continue | |
| requirement = Requirement(line) | |
| if requirement.marker and not requirement.marker.evaluate(): | |
| continue | |
| try: | |
| installed = version(requirement.name) | |
| except PackageNotFoundError: | |
| missing.append(requirement.name) | |
| continue | |
| if not requirement.specifier.contains(installed, prereleases=True): | |
| missing.append(str(requirement)) | |
| if missing: | |
| print('需要安装或更新依赖:' + ', '.join(missing), flush=True) | |
| raise SystemExit(1) | |
| import aiohttp_session, bcrypt, jinja2 | |
| PY_DEPS | |
| then | |
| needs_setup=1 | |
| fi | |
| if [[ "$mode" == --setup-only || "$needs_setup" == 1 ]]; then | |
| if [[ "$EUID" -ne 0 ]]; then echo "依赖安装需要 root;请运行 sudo bash $main_dir/comfyui.sh --setup-only。" >&2; exit 1; fi | |
| # Installed packages must be readable by the comfyui service account. | |
| umask 022 | |
| "$system_python" -m pip install -r requirements.txt -r custom_nodes/ComfyUI-Login/requirements.txt | |
| if [[ -f custom_nodes/seedvr2_videoupscaler/requirements.txt ]]; then | |
| "$system_python" -m pip install -r custom_nodes/seedvr2_videoupscaler/requirements.txt | |
| fi | |
| umask 027 | |
| fi | |
| if [[ "$EUID" -eq 0 ]]; then | |
| install -d -m 700 -o comfyui -g comfyui /var/lib/comfyui /var/lib/comfyui/.cache | |
| install -d -m 750 -o root -g comfyui "$login_dir" | |
| install -d -m 700 /var/lib/comfyui-admin | |
| for writable_dir in "$main_dir/ComfyUI/input" "$main_dir/ComfyUI/user" \ | |
| "$main_dir/comfyui-output"; do | |
| install -d -m 750 -o comfyui -g comfyui "$writable_dir" | |
| chown -R --no-dereference comfyui:comfyui "$writable_dir" | |
| done | |
| "$system_python" -I - "$login_dir" <<'PY' | |
| import base64 | |
| from datetime import datetime | |
| import os | |
| from pathlib import Path | |
| import pwd | |
| import secrets | |
| import sys | |
| import bcrypt | |
| account = pwd.getpwnam('comfyui') | |
| config = Path(sys.argv[1]) | |
| password_file = config / 'PASSWORD' | |
| if not password_file.exists(): | |
| password = secrets.token_urlsafe(24) | |
| password_file.write_bytes(bcrypt.hashpw(password.encode(), bcrypt.gensalt()) + b'\ncomfyui\n') | |
| credentials = Path('/var/lib/comfyui-admin/login.txt') | |
| credentials.write_text('Username: comfyui\nPassword: ' + password + '\n') | |
| credentials.chmod(0o600) | |
| print('已生成登录密码:/var/lib/comfyui-admin/login.txt(仅 root 可读)') | |
| os.chown(password_file, 0, account.pw_gid) | |
| password_file.chmod(0o640) | |
| key_file = config / '.secret-key.txt' | |
| if not key_file.exists(): | |
| key_file.write_text(base64.urlsafe_b64encode(os.urandom(32)).decode() + ',' + datetime.now().isoformat()) | |
| os.chown(key_file, account.pw_uid, account.pw_gid) | |
| key_file.chmod(0o600) | |
| PY | |
| fi | |
| # Refuse startup if an update removed the login checks or credentials. | |
| "$system_python" -I - "$main_dir/ComfyUI" "$login_dir" <<'PY' | |
| from pathlib import Path | |
| import sys | |
| import aiohttp_session | |
| import bcrypt | |
| import jinja2 | |
| root, config = map(Path, sys.argv[1:]) | |
| assert 'COMFYUI_REQUIRE_LOGIN' in (root / 'main.py').read_text(), '登录启动检查缺失,请恢复后再启动。' | |
| assert 'COMFYUI_LOGIN_DIR' in (root / 'custom_nodes/ComfyUI-Login/password.py').read_text(), '登录插件配置支持缺失,请恢复后再启动。' | |
| assert (config / 'PASSWORD').is_file(), '请先以 root 运行本脚本初始化密码。' | |
| assert not (config / 'GUEST_MODE').exists(), '请关闭 GUEST_MODE 后启动。' | |
| bcrypt.checkpw(b'configuration-check', (config / 'PASSWORD').read_bytes().splitlines()[0]) | |
| PY | |
| if [[ "$mode" == --setup-only ]]; then echo "依赖和低权限账户已准备好。"; exit 0; fi | |
| echo "ComfyUI-Login 已配置;使用 comfyui 用户运行,默认监听 0.0.0.0:8188;可通过启动参数覆盖。" | |
| echo "查看登录密码:sudo cat /var/lib/comfyui-admin/login.txt" | |
| echo "前台运行;按 Ctrl+C 停止。" | |
| runtime_env=(env -i PATH=/usr/local/bin:/usr/bin:/bin HOME=/var/lib/comfyui USER=comfyui LOGNAME=comfyui \ | |
| LANG=C.UTF-8 LC_ALL=C.UTF-8 USE_TF=0 USE_FLAX=0 PYTHONNOUSERSITE=1 PYTHONDONTWRITEBYTECODE=1 \ | |
| PYTHONUNBUFFERED=1 COMFYUI_REQUIRE_LOGIN=1 COMFYUI_LOGIN_DIR="$login_dir" \ | |
| TORCH_FORCE_WEIGHTS_ONLY_LOAD=1) | |
| if [[ -n "${CUDA_VISIBLE_DEVICES+x}" ]]; then runtime_env+=(CUDA_VISIBLE_DEVICES="$CUDA_VISIBLE_DEVICES"); fi | |
| command=("${runtime_env[@]}" "$system_python" main.py --listen 0.0.0.0 --port 8188 \ | |
| --output-directory "$main_dir/comfyui-output" --temp-directory /var/lib/comfyui "$@") | |
| if [[ "$EUID" -eq 0 ]]; then | |
| exec setpriv --reuid=comfyui --regid=comfyui --init-groups --bounding-set=-all \ | |
| --inh-caps=-all --ambient-caps=-all --no-new-privs "${command[@]}" | |
| fi | |
| exec setpriv --no-new-privs "${command[@]}" | |
Xet Storage Details
- Size:
- 7.03 kB
- Xet hash:
- 39689da0a2211eb4c253fb3f7e743f3ed9bd0ffd699d7b3f19cd4e3826091e74
·
Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.