添加部署脚本 deploy.sh
This commit is contained in:
68
deploy.sh
Normal file
68
deploy.sh
Normal file
@@ -0,0 +1,68 @@
|
||||
#!/bin/bash
|
||||
# OpenClaw Memory 部署脚本
|
||||
# 在宿主机运行
|
||||
|
||||
set -e
|
||||
|
||||
echo "☯️ 开始部署 OpenClaw Memory 系统..."
|
||||
|
||||
# 配置
|
||||
DEPLOY_DIR="/app/openclaw-memory"
|
||||
DB_HOST="10.2.0.100"
|
||||
DB_PORT="5432"
|
||||
DB_USER="daotong"
|
||||
DB_PASSWORD="825670@DaotongSql"
|
||||
DB_NAME="daotong"
|
||||
SERVICE_PORT="8087"
|
||||
|
||||
# 检查目录
|
||||
if [ ! -d "$DEPLOY_DIR" ]; then
|
||||
echo "❌ 部署目录不存在: $DEPLOY_DIR"
|
||||
echo "请先克隆代码库:"
|
||||
echo "git clone http://10.2.0.100:8989/daotong/openclaw-memory.git $DEPLOY_DIR"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
cd "$DEPLOY_DIR/backend"
|
||||
|
||||
# 配置环境变量
|
||||
cat > .env << EOF
|
||||
DB_HOST=$DB_HOST
|
||||
DB_PORT=$DB_PORT
|
||||
DB_USER=$DB_USER
|
||||
DB_PASSWORD=$DB_PASSWORD
|
||||
DB_NAME=$DB_NAME
|
||||
EOF
|
||||
|
||||
echo "📦 安装依赖..."
|
||||
pip3 install -q -r requirements.txt
|
||||
|
||||
echo "🗄️ 运行数据库迁移..."
|
||||
python3 manage.py migrate
|
||||
|
||||
echo "🚀 启动服务(端口 $SERVICE_PORT)..."
|
||||
# 杀掉旧进程
|
||||
pkill -f "python3 manage.py runserver $SERVICE_PORT" 2>/dev/null || true
|
||||
|
||||
# 启动新服务
|
||||
mkdir -p ../logs
|
||||
nohup python3 manage.py runserver 0.0.0.0:$SERVICE_PORT > ../logs/server.log 2>&1 &
|
||||
|
||||
sleep 3
|
||||
|
||||
# 检查服务状态
|
||||
if curl -s "http://localhost:$SERVICE_PORT/api/stats/" > /dev/null; then
|
||||
echo "✅ 服务启动成功!"
|
||||
echo "📍 API 地址: http://localhost:$SERVICE_PORT/api/"
|
||||
echo "📊 统计接口: http://localhost:$SERVICE_PORT/api/stats/"
|
||||
else
|
||||
echo "❌ 服务启动失败,查看日志:"
|
||||
tail -20 ../logs/server.log
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo ""
|
||||
echo "📝 常用命令:"
|
||||
echo " 查看日志: tail -f $DEPLOY_DIR/logs/server.log"
|
||||
echo " 停止服务: pkill -f 'python3 manage.py runserver $SERVICE_PORT'"
|
||||
echo " 重启服务: bash $0"
|
||||
Reference in New Issue
Block a user