Files
gangyan/scripts/log-trim-daemon.sh
liuguancen 0c3a393d04 [运维] 接入内网 searxng + 清理启动脚本 + 修 log-trim 权限
搜索接口:

- duckduckgo_search.py / ZhipuSearchAPI.py 切换到内网 searxng (原 43.251.225.121 / 134.122.191.214 已失效)

启动脚本清理:

- 删除废弃 backend/ 目录 (与 chat_web_backend/ 编译产物 jar MD5 相同,仅是改名副本)

- 删除 start_all.sh 与 langchain-chat/{start,stop,stop_quick,shutdown_all,restart}.sh (被 scripts/*-restart.sh 覆盖)

- 删除 chat_web_backend/{start,test_mysql}.sh

修复:

- scripts/backend-restart.sh 对齐当前实际在跑的 chat_web_backend.jar (profile=dev)

- scripts/log-trim-daemon.sh 把 LOCK 移到 /tmp 按用户命名,修复非首次用户跑时的 Permission denied

新增:

- scripts/start-all.sh:一键启动入口,串联 mysql/redis/milvus/langchain/backend/frontend,含端口自检

- chat_web_backend/application-local.yml.archived:原 backend/ 下 yj profile 覆盖配置的归档备份

其他:

- .gitignore 忽略 scripts/pptist-deploy/PPTist/ (323M 第三方源码树)
2026-04-20 15:59:11 +08:00

61 lines
1.7 KiB
Bash
Executable File
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.

#!/usr/bin/env bash
# Keep a log file capped by trimming from the front.
# Usage:
# ./log-trim-daemon.sh --file /path/to/app.log --max-mb 5 --interval-sec 3
set -euo pipefail
FILE=""
MAX_MB=5
INTERVAL_SEC=3
while [ $# -gt 0 ]; do
case "$1" in
--file) FILE="${2:-}"; shift 2 ;;
--max-mb) MAX_MB="${2:-}"; shift 2 ;;
--interval-sec) INTERVAL_SEC="${2:-}"; shift 2 ;;
-h|--help)
echo "Usage: $0 --file PATH [--max-mb 5] [--interval-sec 3]"
exit 0
;;
*)
echo "Unknown arg: $1" >&2
exit 2
;;
esac
done
if [ -z "${FILE}" ]; then
echo "Missing --file" >&2
exit 2
fi
MAX_BYTES=$((MAX_MB * 1024 * 1024))
TMP="${FILE}.trimtmp.$$"
# LOCK 放 /tmp 并按用户命名,避免不同用户启动时 .trimlock owner 错配导致 Permission denied
LOCK="/tmp/gangyan-trim-$(basename "$FILE").$(id -un).lock"
mkdir -p "$(dirname "$FILE")"
touch "$FILE" 2>/dev/null || true
while true; do
if [ -f "$FILE" ]; then
size=$(stat -c%s "$FILE" 2>/dev/null || echo 0)
if [ "${size:-0}" -gt "$MAX_BYTES" ]; then
# Keep only the last MAX_BYTES bytes.
# IMPORTANT: do NOT replace the file inode (mv),否则 tail -f/编辑器可能还在看旧 inode
# 会出现“日志不更新/看不到最新内容”的错觉。这里用 copy+truncate 保持 inode 不变。
(
flock -w 2 9 || exit 0
tail -c "$MAX_BYTES" "$FILE" > "$TMP" 2>/dev/null || true
# 覆盖写回同一文件inode 不变)
if [ -s "$TMP" ]; then
cat "$TMP" > "$FILE" 2>/dev/null || true
fi
rm -f "$TMP" 2>/dev/null || true
) 9>"$LOCK" || true
fi
fi
sleep "$INTERVAL_SEC"
done