fix: 添加PostgreSQL启动超时处理

This commit is contained in:
Sens 2026-02-20 23:18:10 +08:00
parent 809ff9428c
commit 0e252281cd
1 changed files with 16 additions and 2 deletions

View File

@ -88,9 +88,23 @@ echo -e "${YELLOW}[2/9] 配置 PostgreSQL 数据库...${NC}"
apt-get install -y --no-install-recommends postgresql postgresql-contrib || true apt-get install -y --no-install-recommends postgresql postgresql-contrib || true
systemctl start postgresql # 启动 PostgreSQL
systemctl enable postgresql echo "启动 PostgreSQL..."
systemctl start postgresql || true
systemctl enable postgresql || true
# 等待 PostgreSQL 就绪 (最多等待 30 秒)
echo "等待 PostgreSQL 就绪..."
for i in {1..30}; do
if su - postgres -c "psql -c 'SELECT 1;'" > /dev/null 2>&1; then
echo "PostgreSQL 已就绪"
break
fi
sleep 1
done
# 创建数据库
echo "创建数据库..."
su - postgres -c "psql -c \"CREATE DATABASE neural_sync;\"" 2>/dev/null || true su - postgres -c "psql -c \"CREATE DATABASE neural_sync;\"" 2>/dev/null || true
su - postgres -c "psql -c \"CREATE USER neuraluser WITH PASSWORD '$DB_PASSWORD';\"" 2>/dev/null || true su - postgres -c "psql -c \"CREATE USER neuraluser WITH PASSWORD '$DB_PASSWORD';\"" 2>/dev/null || true
su - postgres -c "psql -c \"GRANT ALL PRIVILEGES ON DATABASE neural_sync TO neuraluser;\"" 2>/dev/null || true su - postgres -c "psql -c \"GRANT ALL PRIVILEGES ON DATABASE neural_sync TO neuraluser;\"" 2>/dev/null || true