fix: deploy.sh/test.sh 审计修复
Some checks failed
Deploy Backend / deploy (push) Has been cancelled

deploy.sh:
- 修复重复的 header 注释行

lib/common.sh:
- view_logs/tail_logs/status: 从日志文件切换为 journalctl(上次改
  日志输出到 stdout 后,日志文件已不存在)
- init_env 模板: User=root → User=rust-backend(匹配最小权限原则)

lib/test.sh:
- test_notify_url_domain: 添加自定义 Host 头(TEST_DOMAIN),模拟
  真实外部请求场景。之前测试走 127.0.0.1 直连,Host 头为 localhost
  导致 notify_url 校验永远通过但实际配置可能是错误的
This commit is contained in:
2026-07-23 12:25:46 +08:00
parent 0b0757939b
commit 217e7f8a55
3 changed files with 20 additions and 26 deletions

View File

@@ -187,8 +187,8 @@ Wants=network.target
[Service]
Type=simple
User=root
Group=root
User=rust-backend
Group=rust-backend
WorkingDirectory=${REMOTE_DIR}
ExecStart=${REMOTE_DIR}/rust-backend
Restart=always
@@ -403,19 +403,15 @@ rollback_on_failure() {
view_logs() {
local lines="${LOG_LINES:-50}"
log_step "查看后端日志(最后 ${lines} 行)..."
[ "$DRY_RUN" = true ] && { log_dry "tail -${lines} 日志文件"; return 0; }
local lf; lf=$(remote "ls -t ${REMOTE_DIR}/logs/rust-backend.*.log 2>/dev/null | head -1" || echo "")
[ -z "$lf" ] && { log_warn "未找到日志文件"; return 1; }
echo -e "${BLUE}=== ${lf} ===${NC}"; remote "tail -${lines} '${lf}'"
[ "$DRY_RUN" = true ] && { log_dry "journalctl -u ${SERVICE_NAME} -n ${lines}"; return 0; }
remote "journalctl -u ${SERVICE_NAME} -n ${lines} --no-pager 2>/dev/null" || log_warn "无法读取 journalctl 日志"
}
tail_logs() {
local lines="${LOG_LINES:-100}"
log_step "实时跟踪日志..."
[ "$DRY_RUN" = true ] && return 0
local lf; lf=$(remote "ls -t ${REMOTE_DIR}/logs/rust-backend.*.log 2>/dev/null | head -1" || echo "")
[ -z "$lf" ] && { log_warn "未找到日志文件"; return 1; }
ssh -t "${REMOTE_USER}@${REMOTE_HOST}" "tail -f -n ${lines} '${lf}'"
ssh -t "${REMOTE_USER}@${REMOTE_HOST}" "journalctl -u ${SERVICE_NAME} -n ${lines} -f"
}
status() {
@@ -423,8 +419,8 @@ status() {
[ "$DRY_RUN" = true ] && { log_dry "systemctl status ${SERVICE_NAME}"; return 0; }
echo -e "${BLUE}=== ${SERVICE_NAME} ===${NC}"
remote "systemctl status ${SERVICE_NAME} --no-pager"
local lf; lf=$(remote "ls -t ${REMOTE_DIR}/logs/rust-backend.*.log 2>/dev/null | head -1" || echo "")
[ -n "$lf" ] && { echo -e "${BLUE}=== 最近日志 ===${NC}"; remote "tail -20 '${lf}'"; }
echo -e "${BLUE}=== 最近日志 ===${NC}"
remote "journalctl -u ${SERVICE_NAME} -n 20 --no-pager 2>/dev/null" || log_warn "无法读取 journalctl 日志"
}
# ---------- 确认 ----------