Files
DFWebOS-Apps/librechat/hooks/pre-start

56 lines
3.5 KiB
Bash
Executable File
Raw Blame History

This file contains invisible Unicode characters
This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#!/usr/bin/env bash
set -euo pipefail
# дозорный файл, чтобы проверить, был ли уже инициализирован пользователь
USER_SENTINEL="${APP_DATA_DIR}/.user_created"
# имя пользователя и адрес электронной почты по умолчанию
USER_NAME="DFWebOS"
USER_EMAIL="dfwebos@dfwebos.local"
# максимальное количество попыток и время ожидания между ними (60 секунд)
MAX_TRIES=12
SLEEP_SECS=5
# ───────────────────────────────────────────────────────────
# Полностью пропустить загрузку, если пользователь уже инициализирован
# ───────────────────────────────────────────────────────────
if [[ -f "$USER_SENTINEL" ]]; then
echo "Librechat: user already initialised - skipping bootstrap."
exit 0
fi
# ───────────────────────────────────────────────────────────
# Подключите весь стек, чтобы миграция выполнялась автоматически.
# Вероятно, здесь можно вызвать только необходимые сервисы, но делаем это для простоты.
# --wait игнорируется в старых версиях Compose (DFWebOS < 1.0)
# ───────────────────────────────────────────────────────────
echo "Librechat: starting full stack to run migrations…"
"${DFWEBOS_ROOT}/scripts/app" compose "${APP_ID}" \
up -d --wait --wait-timeout 90
# ───────────────────────────────────────────────────────────
# Повторяйте попытку, пока пользователь не будет создан (максимум 60 секунд).
# Все контейнеры запущены, поэтому с первой попытки все должно получиться.
# Но включение цикла повторов для надежности
# ───────────────────────────────────────────────────────────
echo "Librechat: ensuring user exists…"
for ((try=1; try<=MAX_TRIES; try++)); do
# - В случае успеха помощник завершает работу из 0, сообщая включающему циклу, что мы закончили.
if "${DFWEBOS_ROOT}/scripts/app" compose "${APP_ID}" exec -T api node config/create-user.js "${USER_EMAIL}" "${USER_NAME}" "${USER_NAME}" "${APP_PASSWORD}" --email-verified=true ; then
touch "$USER_SENTINEL"
echo "Librechat: user ready."
break
fi
echo " Attempt $try/$MAX_TRIES failed - retrying in ${SLEEP_SECS}s…"
sleep "$SLEEP_SECS"
done
if [[ ! -f "$USER_SENTINEL" ]]; then
echo "Librechat ERROR: could not create user after $MAX_TRIES attempts."
exit 1
fi
echo "Librechat: bootstrap finished - stopping stack for clean start…"
"${DFWEBOS_ROOT}/scripts/app" compose "${APP_ID}" stop