Files
nxxmdata/insurance_backend/restart-backend.sh
2025-09-30 17:41:21 +08:00

61 lines
1.3 KiB
Bash
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/bin/bash
# 重启保险后端服务脚本
echo "🔄 重启保险后端服务..."
# 设置工作目录
cd /var/www/insurance-backend
# 停止现有服务
echo "🛑 停止现有服务..."
pm2 stop insurance-backend 2>/dev/null || true
pkill -f "node.*src/app.js" 2>/dev/null || true
# 等待进程完全停止
sleep 3
# 检查端口是否被释放
if lsof -Pi :3000 -sTCP:LISTEN -t >/dev/null ; then
echo "⚠️ 端口3000仍被占用强制停止..."
sudo fuser -k 3000/tcp 2>/dev/null || true
sleep 2
fi
# 启动服务
echo "🚀 启动服务..."
pm2 start ecosystem.config.js --env production
# 等待服务启动
echo "⏳ 等待服务启动..."
sleep 5
# 检查服务状态
echo "🔍 检查服务状态..."
pm2 status
# 测试API
echo "🧪 测试API..."
for i in {1..3}; do
if curl -s http://127.0.0.1:3000/health > /dev/null; then
echo "✅ API测试成功"
break
else
echo "⏳ 等待API启动... ($i/3)"
sleep 2
fi
done
# 保存PM2配置
pm2 save
echo ""
echo "✅ 服务重启完成!"
echo "📋 服务信息:"
echo " 服务名称: insurance-backend"
echo " 端口: 3000"
echo " 环境: production"
echo ""
echo "🔍 查看日志: pm2 logs insurance-backend"
echo "📊 监控面板: pm2 monit"