fix: ожидание PostgreSQL при старте, скрипт fix-db-connection
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -252,6 +252,35 @@ shop.example.com {
|
||||
|
||||
Порты **80/443** открыть; **5432** и **3000** наружу не публиковать.
|
||||
|
||||
### Ошибка `ECONNREFUSED 127.0.0.1:5432`
|
||||
|
||||
Приложение обновилось на PostgreSQL, а сервер БД не запущен.
|
||||
|
||||
**Быстрое исправление (одной командой):**
|
||||
|
||||
```bash
|
||||
cd /opt/shop
|
||||
git pull
|
||||
bash scripts/fix-db-connection.sh
|
||||
```
|
||||
|
||||
**Вручную:**
|
||||
|
||||
```bash
|
||||
apt install -y postgresql-17 postgresql-client-17
|
||||
systemctl enable --now postgresql
|
||||
pg_isready -h 127.0.0.1 -p 5432
|
||||
|
||||
cd /opt/shop
|
||||
bash scripts/setup-postgres-ubuntu.sh
|
||||
nano .env # DATABASE_URL=postgresql://shop:shop@127.0.0.1:5432/shop
|
||||
|
||||
cp deploy/shop.service /etc/systemd/system/shop.service
|
||||
systemctl daemon-reload
|
||||
systemctl restart shop
|
||||
curl -s http://127.0.0.1:3000/health
|
||||
```
|
||||
|
||||
### HTTP 502
|
||||
|
||||
```bash
|
||||
@@ -261,7 +290,8 @@ journalctl -u shop -n 50 --no-pager
|
||||
|
||||
| Причина | Решение |
|
||||
|--------|---------|
|
||||
| PostgreSQL не запущен | `systemctl start postgresql` |
|
||||
| `ECONNREFUSED 127.0.0.1:5432` | PostgreSQL не запущен или не установлен — см. ниже |
|
||||
| PostgreSQL не запущен | `systemctl enable --now postgresql` |
|
||||
| Неверный `DATABASE_URL` | проверить `.env`, `psql` |
|
||||
| Node не слушает 3000 | `journalctl -u shop -f` |
|
||||
| Caddy без backend | сначала `curl /health`, потом `reload caddy` |
|
||||
@@ -294,6 +324,7 @@ caddy/Caddyfile.example
|
||||
deploy/shop.service
|
||||
scripts/
|
||||
setup-postgres-ubuntu.sh
|
||||
fix-db-connection.sh
|
||||
diagnose-502.sh
|
||||
server-update.sh
|
||||
src/
|
||||
|
||||
Reference in New Issue
Block a user