把原本散落在 /root/zikai 的 FastAPI 服务整理到 server/ 子目录, 开启独立 git 与 venv。运行时数据(config.yaml / keys / uploads) 按 .gitignore 留在工作目录但不入仓。
38 lines
1.1 KiB
Bash
Executable File
38 lines
1.1 KiB
Bash
Executable File
#!/usr/bin/env bash
|
||
# 通过 pidfile 优雅停止 SFTP 与 HTTP,超时则 SIGKILL。
|
||
set -uo pipefail
|
||
|
||
cd "$(dirname "$0")"
|
||
ROOT="$(pwd)"
|
||
|
||
stop_pidfile() {
|
||
local name="$1" pidfile="$2"
|
||
if [ ! -f "$pidfile" ]; then
|
||
echo "$name: 无 pidfile ($pidfile),未运行。"
|
||
return 0
|
||
fi
|
||
local pid; pid="$(cat "$pidfile" 2>/dev/null || true)"
|
||
if [ -z "$pid" ] || ! kill -0 "$pid" 2>/dev/null; then
|
||
rm -f "$pidfile"
|
||
echo "$name: 进程已退出,清理 pidfile。"
|
||
return 0
|
||
fi
|
||
echo "$name: SIGTERM -> $pid ..."
|
||
kill -TERM "$pid" 2>/dev/null || true
|
||
for _ in $(seq 1 20); do
|
||
kill -0 "$pid" 2>/dev/null || break
|
||
sleep 0.25
|
||
done
|
||
if kill -0 "$pid" 2>/dev/null; then
|
||
echo "$name: 仍在运行,发送 SIGKILL..."
|
||
kill -KILL "$pid" 2>/dev/null || true
|
||
fi
|
||
rm -f "$pidfile"
|
||
echo "$name: 已停止。"
|
||
}
|
||
|
||
# 先停 SFTP(避免拆解过程中又有新文件落盘),再停 HTTP。
|
||
stop_pidfile "SFTP" "$ROOT/sftp.pid"
|
||
stop_pidfile "HTTP" "$ROOT/app.pid"
|
||
echo "全部服务已停止。"
|