#!/bin/bash
# 管理会计OS — 后端生产部署脚本（systemd 方式）
set -e

cd "$(dirname "$0")"

echo "===== CMA 后端部署 ====="

if [ ! -f .env ]; then
  echo "[!] 缺少 .env 文件"
  exit 1
fi

# 安装依赖
pip install -r requirements.txt --quiet --no-cache-dir
echo "[✓] 依赖安装完成"

# 重启 systemd 服务
systemctl daemon-reload
systemctl restart cma-backend
systemctl status cma-backend --no-pager | head -5

echo "[✓] 部署完成"
echo "    systemctl status cma-backend    # 查看状态"
echo "    journalctl -u cma-backend -f    # 查看日志"
