/
kreyndelHam
/
Konstructorium
Обзор
Документация
Войти
/
kreyndelHam
/
Konstructorium
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
1
CI/CD
Аналитика
Безопасность
dev
scripts/ci/gitverse/smoke_stack_lib.sh
116 строк
3 KB
MihahamYT
Start service in CI
17 май 2026, 19:50
17 май 2026, 19:50
0427a0d
Код
Авторство
О чём код?
#!/usr/bin/env bash # # Shared PID paths and helpers for the GitVerse API smoke CI job. # Sourced by other scripts in this directory; do not execute directly. SMOKE_GUNICORN_PID_FILES=( /tmp/gunicorn-auth.pid /tmp/gunicorn-user.pid /tmp/gunicorn-admin.pid /tmp/gunicorn-chat.pid /tmp/gunicorn-analytics.pid /tmp/gunicorn-product.pid /tmp/gunicorn-review.pid /tmp/gunicorn-order.pid ) SMOKE_ALL_PID_FILES=( "${SMOKE_GUNICORN_PID_FILES[@]}" /tmp/telegram-bot.pid ) # Force-stop processes listed in PID files (used after pytest). smoke_force_kill_pid_files() { local f pid for f in "${SMOKE_ALL_PID_FILES[@]}"; do if [[ ! -f "$f" ]]; then continue fi pid="$(tr -d '[:space:]' < "$f")" if [[ -n "$pid" ]] && [[ "$pid" -eq "$pid" ]] 2>/dev/null && kill -0 "$pid" 2>/dev/null; then kill "$pid" 2>/dev/null || true local _ for _ in $(seq 1 15); do if ! kill -0 "$pid" 2>/dev/null; then break fi sleep 1 done kill -9 "$pid" 2>/dev/null || true fi rm -f "$f" done } # Start one gunicorn process with CI env (DATABASE_URL, SECRET_KEY, REDIS_URL). smoke_start_gunicorn() { local service_dir="$1" local wsgi_module="$2" local bind_addr="$3" local log_path="$4" local pid_path="$5" local database_url="${6:-${DATABASE_URL:-}}" if [[ -z "${SECRET_KEY:-}" ]]; then echo "::error::SECRET_KEY is not set; run prepare_runtime_secret_key.sh first." return 1 fi if [[ -z "$database_url" ]]; then echo "::error::DATABASE_URL is not set for ${service_dir}." return 1 fi ( cd "$service_dir" DATABASE_URL="$database_url" \ SECRET_KEY="$SECRET_KEY" \ REDIS_URL="${REDIS_URL:-redis://127.0.0.1:6379/0}" \ nohup gunicorn "$wsgi_module" --bind "$bind_addr" --workers 2 \ >"$log_path" 2>&1 & echo $! >"$pid_path" ) } # Fail fast when a background gunicorn process died during startup. smoke_assert_gunicorn_pids_alive() { local entry label pid_file pid local -a targets=( "auth_service|/tmp/gunicorn-auth.pid" "user_service|/tmp/gunicorn-user.pid" "admin_service|/tmp/gunicorn-admin.pid" "chat_service|/tmp/gunicorn-chat.pid" "analytics_service|/tmp/gunicorn-analytics.pid" "product_service|/tmp/gunicorn-product.pid" "order_service|/tmp/gunicorn-order.pid" "review_service|/tmp/gunicorn-review.pid" ) for entry in "${targets[@]}"; do IFS='|' read -r label pid_file <<<"$entry" if ! pid="$(tr -d '[:space:]' < "$pid_file" 2>/dev/null)" || [[ -z "$pid" ]]; then echo "::error::Missing PID file for ${label} (${pid_file})" return 1 fi if ! kill -0 "$pid" 2>/dev/null; then echo "::error::${label} gunicorn exited during startup (pid=${pid})." return 1 fi done } # Best-effort SIGTERM for cleanup (always() step). smoke_stop_pid_files_best_effort() { local f pid for f in "${SMOKE_ALL_PID_FILES[@]}"; do if [[ ! -f "$f" ]]; then continue fi pid="$(tr -d '[:space:]' < "$f")" if [[ -n "$pid" ]] && [[ "$pid" -eq "$pid" ]] 2>/dev/null; then kill "$pid" 2>/dev/null || true else echo "Skip invalid pid file: $f" fi rm -f "$f" done }