From 0c1eb3eae21e0d275da786db7c03aa22b60c9eb4 Mon Sep 17 00:00:00 2001 From: shaw Date: Wed, 6 Aug 2025 13:50:30 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=E5=A4=9A=E4=B8=AA?= =?UTF-8?q?=E9=83=A8=E7=BD=B2=E5=92=8C=E7=AE=A1=E7=90=86=E8=84=9A=E6=9C=AC?= =?UTF-8?q?=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 修复workflow中web-dist分支推送node_modules的问题 - 添加.gitignore文件排除node_modules - 使用git add --all -- ':\!node_modules'命令排除node_modules目录 - 修复scripts/manage.sh脚本问题 - 移除软链创建时的覆盖询问,默认使用代码中的最新版本 - 安装时自动给scripts/manage.sh添加执行权限 - 创建软链时确保目标脚本有执行权限 - 修复CentOS 9系统上服务启动失败的问题 - 改进systemd服务配置,添加环境变量和日志目录创建 - 添加systemctl daemon-reload确保配置生效 - 增加启动状态检查和失败时的npm回退机制 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude --- .github/workflows/auto-release-pipeline.yml | 12 ++++- scripts/manage.sh | 53 +++++++++++++++------ 2 files changed, 48 insertions(+), 17 deletions(-) diff --git a/.github/workflows/auto-release-pipeline.yml b/.github/workflows/auto-release-pipeline.yml index 1ce2e48f..ace0e30c 100644 --- a/.github/workflows/auto-release-pipeline.yml +++ b/.github/workflows/auto-release-pipeline.yml @@ -194,8 +194,16 @@ jobs: Build Date: $(date -u +"%Y-%m-%d %H:%M:%S UTC") EOF - # 提交并推送 - git add -A + # 创建 .gitignore 文件以排除 node_modules + cat > .gitignore << EOF + node_modules/ + *.log + .DS_Store + .env + EOF + + # 只添加必要的文件,排除 node_modules + git add --all -- ':!node_modules' git commit -m "chore: update frontend build for v${{ steps.next_version.outputs.new_version }} [skip ci]" git push origin web-dist --force diff --git a/scripts/manage.sh b/scripts/manage.sh index 31c8d38a..320846b5 100644 --- a/scripts/manage.sh +++ b/scripts/manage.sh @@ -421,6 +421,12 @@ install_service() { print_info "安装项目依赖..." npm install + # 确保脚本有执行权限 + if [ -f "$APP_DIR/scripts/manage.sh" ]; then + chmod +x "$APP_DIR/scripts/manage.sh" + print_success "已设置脚本执行权限" + fi + # 创建配置文件 print_info "创建配置文件..." @@ -562,11 +568,15 @@ After=network.target redis.service Type=simple User=$USER WorkingDirectory=$APP_DIR +Environment="NODE_ENV=production" +EnvironmentFile=-$APP_DIR/.env ExecStart=$(which node) $APP_DIR/src/app.js Restart=on-failure RestartSec=10 StandardOutput=append:$APP_DIR/logs/service.log StandardError=append:$APP_DIR/logs/service-error.log +# 确保日志目录存在 +ExecStartPre=/bin/mkdir -p $APP_DIR/logs [Install] WantedBy=multi-user.target @@ -743,8 +753,27 @@ start_service() { # 使用不同方式启动 if [ -f "/etc/systemd/system/claude-relay.service" ]; then + # 先重新加载systemd配置 + sudo systemctl daemon-reload + + # 启动服务 sudo systemctl start claude-relay.service - print_success "服务已通过 systemd 启动" + + # 等待服务启动 + sleep 3 + + # 检查服务状态 + if sudo systemctl is-active claude-relay.service >/dev/null 2>&1; then + print_success "服务已通过 systemd 启动" + else + print_warning "systemd 启动失败,尝试使用 npm 启动..." + # 查看失败原因 + sudo journalctl -u claude-relay.service -n 20 --no-pager 2>/dev/null + + # 尝试使用npm启动 + npm run service:start:daemon + print_success "服务已通过 npm 启动" + fi else # 使用npm启动 npm run service:start:daemon @@ -1090,6 +1119,8 @@ create_symlink() { # 优先使用项目中的 manage.sh(在 app/scripts 目录下) if [ -n "$APP_DIR" ] && [ -f "$APP_DIR/scripts/manage.sh" ]; then script_path="$APP_DIR/scripts/manage.sh" + # 确保脚本有执行权限 + chmod +x "$script_path" 2>/dev/null || sudo chmod +x "$script_path" 2>/dev/null || true elif [ -f "/app/scripts/manage.sh" ] && [ "$(basename "$0")" = "manage.sh" ]; then # Docker 容器中的路径 script_path="/app/scripts/manage.sh" @@ -1124,21 +1155,13 @@ create_symlink() { return 1 fi - # 检查是否已存在 + # 如果已存在,直接删除并重新创建(默认使用代码中的最新版本) if [ -L "$symlink_path" ] || [ -f "$symlink_path" ]; then - print_warning "$symlink_path 已存在" - echo -n "是否覆盖?(y/N): " - read -n 1 overwrite - echo - - if [[ "$overwrite" =~ ^[Yy]$ ]]; then - sudo rm -f "$symlink_path" || { - print_error "删除旧文件失败" - return 1 - } - else - return 0 - fi + print_info "更新已存在的软链接..." + sudo rm -f "$symlink_path" 2>/dev/null || { + print_error "删除旧文件失败" + return 1 + } fi # 创建软链接