Skip to content

۲۱ — 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

دستی روی سرور

bash
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.jssudo systemctl restart takeeat
Caddy (reverse proxy)sudo systemctl restart caddy
Postgres + Redisdocker-compose up -d (در /opt/takeeat)

لاگ اپ

bash
journalctl -u takeeat -f          # live
journalctl -u takeeat -n 100        # آخرین ۱۰۰ خط

health check

bash
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/componentnpm test
API integration با DB/Redis واقعیnpm run test:integration
همه تست‌های CInpm run test:ci
راه‌اندازی DB تست لوکالnpm run db:test:setup

راه‌اندازی لوکال integration:

bash
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 روی سرور

bash
grep -E 'SMS_|PANELCHI_|KAVENEGAR_' /opt/takeeat/.env.local
envstageprod
SMS_DEV_MODEtrue (OTP روی صفحه)false
PANELCHI_API_KEYباید پر باشد برای SMS واقعیباید پر باشد
PANELCHI_OTP_PATTERNtakeeat-otpهمان

تست OTP

bash
cd /opt/takeeat
bash scripts/test-otp-send.sh 09xxxxxxxxx
bash scripts/test-panelchi-send.sh   # اگر موجود

بررسی DB

bash
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در حال ارسال
sentOK
failedprovider 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_endno_show
sendPickupReminders()SMS ۳۰–۶۰ min قبل از pickup_end
expireUnconfirmedOrders()awaiting_vendor بعد از pickup_startcancelled
expireBoxes()باکس active بعد از pickup_endexpired

تست دستی cron

bash
curl -X POST -H "x-cron-secret: $CRON_SECRET" https://stage.takeeat.ir/api/cron/tick

CRON_SECRET از .env.local — هرگز commit نکنید.

Admin password migration (یک‌بار)

Legacy SHA-256 admin hashes با login بعدی auto-rehash می‌شوند. برای audit:

bash
npx tsx --env-file=.env.local scripts/migrate-admin-passwords.ts

۵. Database

migrate (بعد از pull)

bash
cd /opt/takeeat
npx prisma migrate deploy

seed (refresh pickup windows — stage)

bash
npm run db:seed

backup (پیشنهاد روزانه)

bash
docker-compose exec -T postgres pg_dump -U takeeat takeeat \
  | gzip > /opt/backups/takeeat-$(date +%Y%m%d).sql.gz

cron 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.gz

restore

bash
gunzip -c backup.sql.gz | docker-compose exec -T postgres psql -U takeeat -d takeeat

۶. SSL

bash
cd /opt/takeeat
bash scripts/obtain-origin-certs.sh   # اولین بار — نیاز ARVAN_API_KEY
sudo certbot renew --dry-run          # تست تمدید
sudo systemctl restart caddy

18-deploy-and-dns.md


۷. Stage vs Prod

موردStageProd
URLstage.takeeat.irapp.takeeat.ir
BLOCK_SEARCH_INDEXINGtruefalse
SMS_DEV_MODEمعمولاً truefalse
ZARINPAL_SANDBOXtruefalse
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.shdeploy کامل
scripts/bootstrap-stage-server.shsetup اولیه سرور
scripts/restart.shkill + build + start (local)
scripts/check-notifications.shآخرین OTP در DB
scripts/backup-db.shbackup Postgres
scripts/restore-db.shrestore از backup
scripts/setup-ops.shKuma + Caddy auth + cron
scripts/setup-ops-dns.shDNS docs/status
scripts/seed-kuma-monitors.mjsmonitors Uptime Kuma
scripts/test-otp-send.shتست OTP API
scripts/set-nic-verify.shفایل verify IRNIC
scripts/obtain-origin-certs.shSSL origin