akira / scripts /init_pg.sh
akra35567's picture
fix: startup - 1 worker, timeout 90s, debug logs in _setup_providers and _setup_hf_inference
d9a5c79
Raw
History Blame Contribute Delete
1.19 kB
#!/bin/bash
# init_pg.sh β€” Inicia PostgreSQL + restaura backup + sobe app FastAPI com 2 workers
set -e
echo "πŸ”§ [INIT] Iniciando PostgreSQL..."
su - postgres -c "pg_ctl -D $PGDATA start" 2>/dev/null || pg_ctlcluster 17 main start 2>/dev/null || service postgresql start
for i in $(seq 1 30); do
if pg_isready -q 2>/dev/null; then
echo "βœ… [INIT] PostgreSQL pronto"
break
fi
sleep 1
done
su - postgres -c "psql -tc \"SELECT 1 FROM pg_roles WHERE rolname='akira'\" | grep -q 1" || \
su - postgres -c "psql -c \"CREATE USER akira WITH PASSWORD 'akira' SUPERUSER;\""
su - postgres -c "psql -tc \"SELECT 1 FROM pg_database WHERE datname='akira'\" | grep -q 1" || \
su - postgres -c "psql -c \"CREATE DATABASE akira OWNER akira;\""
BACKUP_FILE="/akira/data/cloud_sync/akira_dump.sql"
if [ -f "$BACKUP_FILE" ]; then
echo "πŸ“₯ [INIT] Restaurando backup..."
PGPASSWORD=akira psql -h localhost -U akira -d akira -f "$BACKUP_FILE" 2>/dev/null || true
fi
echo "πŸš€ [INIT] Iniciando Akira FastAPI com 1 worker (async)..."
exec uvicorn main:app \
--host 0.0.0.0 \
--port 7860 \
--timeout-keep-alive 30 \
--limit-concurrency 100