zeabur-startup-order

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Zeabur Startup Order Issues

Zeabur 启动顺序问题

Always use
npx zeabur@latest
to invoke Zeabur CLI.
Never use
zeabur
directly or any other installation method. If
npx
is not available, install Node.js first.
始终使用
npx zeabur@latest
调用 Zeabur CLI。
切勿直接使用
zeabur
或其他任何安装方式。如果没有
npx
,请先安装 Node.js。

Symptom

症状

Connection refused :5432
connection to server at "X" failed
OperationalError: connection failed
Connection refused :5432
connection to server at "X" failed
OperationalError: connection failed

Cause

原因

Service starts before dependency (DB/Redis) is ready.
dependencies
only ensures container start order, NOT that the service is accepting connections.
服务在依赖项(数据库/Redis)就绪前启动。
dependencies
仅确保容器启动顺序,不保证服务已准备好接受连接

Fix (Recommended): healthCheck on dependency services

修复方案(推荐):为依赖服务添加健康检查

Add
healthCheck
to database/Redis services so Zeabur waits until the port is accepting connections before starting dependent services — no need to modify the app's command.
Edit the template YAML (use the
zeabur-template
skill for YAML reference):
yaml
- name: postgresql
  spec:
    ports:
      - id: database
        port: 5432
        type: TCP
    healthCheck:
      type: TCP
      port: database    # references the port ID above
yaml
- name: redis
  spec:
    ports:
      - id: database
        port: 6379
        type: TCP
    healthCheck:
      type: TCP
      port: database
为数据库/Redis服务添加
healthCheck
,这样Zeabur会在依赖服务的端口准备好接受连接后再启动依赖它的服务——无需修改应用的命令。
编辑模板YAML(可使用
zeabur-template
skill作为YAML参考):
yaml
- name: postgresql
  spec:
    ports:
      - id: database
        port: 5432
        type: TCP
    healthCheck:
      type: TCP
      port: database    # references the port ID above
yaml
- name: redis
  spec:
    ports:
      - id: database
        port: 6379
        type: TCP
    healthCheck:
      type: TCP
      port: database

Fix (Alternative): Wait loop in command

修复方案(替代):在命令中添加等待循环

If you can't modify the template (use the
zeabur-template
skill), add wait logic to the app's command (command MUST be inside
source
):
yaml
spec:
  source:
    image: myapp:latest
    command:
      - /bin/sh
      - -c
      - "until nc -z postgres 5432; do sleep 1; done && node server.js"
如果无法修改模板(使用
zeabur-template
skill),可在应用的命令中添加等待逻辑(命令必须放在
source
内):
yaml
spec:
  source:
    image: myapp:latest
    command:
      - /bin/sh
      - -c
      - "until nc -z postgres 5432; do sleep 1; done && node server.js"

Quick Fix

快速修复

If DB is now ready, just restart the failed service:
bash
npx zeabur@latest service restart --id <service-id> -y -i=false
If the issue is specifically about database migration waiting loops rather than startup order, use the
zeabur-migration
skill.
如果数据库现在已就绪,只需重启失败的服务:
bash
npx zeabur@latest service restart --id <service-id> -y -i=false
如果问题是关于数据库迁移等待循环而非启动顺序,请使用
zeabur-migration
skill。