۲۱ — Ops Runbook
عملیات روزمره stage/prod — برای dev و co-founder فنی.
سرور stage: 193.176.242.38 — مسیر /opt/takeeat
URL stage: https://stage.takeeat.ir
Docs: https://docs.takeeat.ir
Monitoring: https://status.takeeat.ir (basic auth)
→ راهاندازی کامل ops stack: 23-self-host-ops.md
۱. Deploy
خودکار (توصیه)
push به stage → GitHub Actions deploy-stage.yml → stage.takeeat.irدستی روی سرور
cd /opt/takeeat
git pull origin stage
bash scripts/deploy-stage.shاسکریپت: docker up → migrate → seed → build → systemctl restart takeeat
Prod (وقتی آماده شد)
GitHub Actions → Deploy Production → approval در Environment production
→ چکلیست: 19-production-launch-checklist.md
۲. سرویسها و restart
| سرویس | دستور |
|---|---|
| اپ Next.js | sudo systemctl restart takeeat |
| Caddy (reverse proxy) | sudo systemctl restart caddy |
| Postgres + Redis | docker-compose up -d (در /opt/takeeat) |
لاگ اپ
journalctl -u takeeat -f # live
journalctl -u takeeat -n 100 # آخرین ۱۰۰ خطhealth check
curl -s -o /dev/null -w '%{http_code}' http://127.0.0.1:3000/
curl -sI https://stage.takeeat.ir | head -5۲.۱ تستها
| هدف | دستور |
|---|---|
| تست سریع unit/API mock/component | npm test |
| API integration با DB/Redis واقعی | npm run test:integration |
| همه تستهای CI | npm run test:ci |
| راهاندازی DB تست لوکال | npm run db:test:setup |
راهاندازی لوکال integration:
docker compose up -d
copy .env.test.example .env.test
npm run db:test:setup
npm run test:integrationاگر integration fail شد، اول DATABASE_URL تست، Redis DB 1 و migrationها را چک کنید. جزئیات کامل: 22-api-integration-tests.md
۳. SMS عیبیابی
env روی سرور
grep -E 'SMS_|PANELCHI_|KAVENEGAR_' /opt/takeeat/.env.local| env | stage | prod |
|---|---|---|
SMS_DEV_MODE | true (OTP روی صفحه) | false |
PANELCHI_API_KEY | باید پر باشد برای SMS واقعی | باید پر باشد |
PANELCHI_OTP_PATTERN | takeeat-otp | همان |
تست OTP
cd /opt/takeeat
bash scripts/test-otp-send.sh 09xxxxxxxxx
bash scripts/test-panelchi-send.sh # اگر موجودبررسی DB
bash scripts/check-notifications.sh
# یا:
docker-compose exec -T postgres psql -U takeeat -d takeeat -c \
"SELECT template, status, provider_ref, sent_at FROM notifications ORDER BY created_at DESC LIMIT 10;"| status | معنی |
|---|---|
queued | در حال ارسال |
sent | OK |
failed | provider error — لاگ journalctl -u takeeat |
chain provider
SMS_DEV_MODE → log only
PANELCHI_* → Panelchi API
KAVENEGAR_* → legacy fallback
هیچکدام → fallback log (SMS واقعی نمیرود!)→ جزئیات: 10-sms-notifications.md
۴. Cron
Cron هر ۵ دقیقه از /api/cron/tick (یا node-cron در dev):
| job | کار |
|---|---|
markNoShows() | confirmed بعد از pickup_end → no_show |
sendPickupReminders() | SMS ۳۰–۶۰ min قبل از pickup_end |
expireUnconfirmedOrders() | awaiting_vendor بعد از pickup_start → cancelled |
expireBoxes() | باکس active بعد از pickup_end → expired |
تست دستی cron
curl -X POST -H "x-cron-secret: $CRON_SECRET" https://stage.takeeat.ir/api/cron/tickCRON_SECRET از .env.local — هرگز commit نکنید.
Admin password migration (یکبار)
Legacy SHA-256 admin hashes با login بعدی auto-rehash میشوند. برای audit:
npx tsx --env-file=.env.local scripts/migrate-admin-passwords.ts۵. Database
migrate (بعد از pull)
cd /opt/takeeat
npx prisma migrate deployseed (refresh pickup windows — stage)
npm run db:seedbackup (پیشنهاد روزانه)
docker-compose exec -T postgres pg_dump -U takeeat takeeat \
| gzip > /opt/backups/takeeat-$(date +%Y%m%d).sql.gzcron example (روی سرور):
0 3 * * * docker-compose -f /opt/takeeat/docker-compose.yml exec -T postgres pg_dump -U takeeat takeeat | gzip > /opt/backups/takeeat-$(date +\%Y\%m\%d).sql.gzrestore
gunzip -c backup.sql.gz | docker-compose exec -T postgres psql -U takeeat -d takeeat۶. SSL
cd /opt/takeeat
bash scripts/obtain-origin-certs.sh # اولین بار — نیاز ARVAN_API_KEY
sudo certbot renew --dry-run # تست تمدید
sudo systemctl restart caddy۷. Stage vs Prod
| مورد | Stage | Prod |
|---|---|---|
| URL | stage.takeeat.ir | app.takeeat.ir |
BLOCK_SEARCH_INDEXING | true | false |
SMS_DEV_MODE | معمولاً true | false |
ZARINPAL_SANDBOX | true | false |
| robots / noindex | بله | خیر |
۸. Incident checklist
□ سایت down? → journalctl -u takeeat + curl localhost:3000
□ SMS نمیرسد? → check-notifications + PANELCHI env
□ پرداخت fail? → Zarinpal callback URL + sandbox flag
□ DB full? → df -h + docker system df
□ بعد از fix → smoke: login OTP → home → box detail۹. اسکریپتهای مفید
| اسکریپت | کار |
|---|---|
scripts/deploy-stage.sh | deploy کامل |
scripts/bootstrap-stage-server.sh | setup اولیه سرور |
scripts/restart.sh | kill + build + start (local) |
scripts/check-notifications.sh | آخرین OTP در DB |
scripts/backup-db.sh | backup Postgres |
scripts/restore-db.sh | restore از backup |
scripts/setup-ops.sh | Kuma + Caddy auth + cron |
scripts/setup-ops-dns.sh | DNS docs/status |
scripts/seed-kuma-monitors.mjs | monitors Uptime Kuma |
scripts/test-otp-send.sh | تست OTP API |
scripts/set-nic-verify.sh | فایل verify IRNIC |
scripts/obtain-origin-certs.sh | SSL origin |