feat: add signal trap and graceful shutdown to dev.sh

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
zerosaturation 2026-04-13 12:46:49 +08:00
parent aad5a16ff9
commit 2382ae880c

View File

@ -7,6 +7,32 @@
set -e set -e
# 信号捕获:优雅退出
cleanup() {
echo ""
echo -e "${YELLOW}🛑 收到停止信号,正在关闭所有服务...${NC}"
# 先杀所有 watcher 和 debounce 进程(防止继续触发重启)
if [ -f /tmp/dev_sh_watchers.tmp ]; then
while read watcher_pid; do
kill "$watcher_pid" 2>/dev/null || true
done < /tmp/dev_sh_watchers.tmp
rm -f /tmp/dev_sh_watchers.tmp
fi
# 清理所有 PID 文件并杀服务进程
for service in activityService galleryService socialService assetService userService gateway; do
pkill -9 -f "$service" 2>/dev/null || true
rm -f "/tmp/dev_sh_${service}.pid" "/tmp/dev_sh_${service}_restart"
echo -e "${YELLOW} 🛑 $service 已停止${NC}"
done
echo -e "${GREEN}✅ 所有服务已关闭${NC}"
exit 0
}
trap cleanup SIGINT SIGTERM
RED='\033[0;31m' RED='\033[0;31m'
GREEN='\033[0;32m' GREEN='\033[0;32m'
YELLOW='\033[1;33m' YELLOW='\033[1;33m'