|
|
2 weeks ago | |
|---|---|---|
| cache | 4 weeks ago | |
| client | 3 weeks ago | |
| common | 2 weeks ago | |
| config | 4 weeks ago | |
| handler | 2 weeks ago | |
| live | 2 weeks ago | |
| logger | 1 month ago | |
| middleware | 4 weeks ago | |
| mock | 2 weeks ago | |
| model | 2 weeks ago | |
| mqtt | 4 weeks ago | |
| route | 2 weeks ago | |
| service | 2 weeks ago | |
| sql | 2 weeks ago | |
| token | 4 weeks ago | |
| tool | 4 weeks ago | |
| vo | 2 weeks ago | |
| websocket | 1 month ago | |
| DESIGN.md | 4 weeks ago | |
| Makefile | 1 month ago | |
| README.md | 2 weeks ago | |
| config-prod.yaml | 2 weeks ago | |
| config.yaml | 2 weeks ago | |
| go.mod | 3 weeks ago | |
| go.sum | 3 weeks ago | |
| main.go | 3 weeks ago | |
| publish-prod.sh | 4 weeks ago | |
README.md
laic-backend
低空智控平台 后端 Go 服务。
生产部署
部署脚本参考 D:/GoProject/roller-service/roller-manage/publish-prod.sh,使用 Supervisor 管理服务。
服务器准备
在生产服务器安装 Supervisor。生产配置保存在仓库根目录的 config-prod.yaml,部署脚本会将它上传为服务器部署目录中的 config.yaml:
sudo apt update
sudo apt install supervisor -y
sudo systemctl enable --now supervisor
生产配置至少包含:
oss:
endpoint: https://obs.cn-east-2.myhuaweicloud.com
access-key: 实际的华为云 OBS AK
secret-key: 实际的华为云 OBS SK
bucket: gcs-edu
region: cn-east-2
use-ssl: true
后端启动时直接读取部署目录下的 config.yaml。本地开发不设置 LAIC_CONFIG_FILE 时读取本地 config.yaml;Supervisor 显式设置 LAIC_CONFIG_FILE=config.yaml。
执行部署
修改 publish-prod.sh 顶部的 REMOTE、REMOTE_DIR 和服务参数,然后执行:
chmod +x publish-prod.sh
./publish-prod.sh
脚本会完成:
- 交叉编译 Linux amd64 二进制。
- 创建远程部署目录、日志目录和备份目录。
- 备份旧二进制和
config.yaml(首次部署没有旧文件时跳过)。 - 将本地
config-prod.yaml上传为远程config.yaml。 - 更新 Supervisor 配置、重启服务并检查状态。
- 启动失败时自动恢复最近的旧二进制。
首次部署前确认远程服务器已安装并运行 Supervisor:
sudo apt update
sudo apt install supervisor -y
sudo systemctl enable --now supervisor
查看状态和日志:
sudo supervisorctl status laic-backend-prod
sudo tail -f /usr/local/laic-backend-prod/log/info.log
sudo tail -f /usr/local/laic-backend-prod/log/err.log
部署目录和服务名可以在 publish-prod.sh 顶部调整。回滚时,脚本会使用远程 backup/ 目录中最近的二进制备份;也可以手工恢复后执行:
sudo supervisorctl restart laic-backend-prod
Payment and SIM schema reconciliation
If a production database was upgraded from an older partial release, back it
up first and then run sql/019_reconcile_payment_schema.sql. The migration is
repeatable and fills missing traffic_order.updated_at, payment fields, pending
order guards, and normalizes legacy empty payment idempotency keys. It also
creates the payment/SIM tables. It does not create orders, charge users, or
create SIM cards. Verify the schema and platform resource pool after it finishes, then
restart the backend before retrying payment.
AGPay returns the WeChat QR code as binary image/png. The backend converts it
to a JSON-safe providerPayload data URI (data:image/png;base64,...); clients
should use that value directly as the image src and must not UTF-8 decode the
original response body.
Test traffic grant
For QA environments, set the following configuration explicitly (it defaults to disabled):
testing:
allow-traffic-grant: true
An authenticated administrator can then credit a regular user without creating a payment order:
POST /v1/admin/traffic/test-grants
Content-Type: application/json
{"userId":8243938201600,"amountGb":10,"reason":"live test"}
The operation updates the user snapshot, appends a test_grant traffic ledger
entry, invalidates the Redis balance cache, and writes an operation log. Keep
the switch disabled in production after testing.