Files
AuthCenterConsoleApp/bash/start_winboll_in_termux_infolog.sh
2026-01-17 05:42:14 +08:00

53 lines
1.9 KiB
Bash
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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.

#!/bin/bash
# Termux专属启动脚本 编译+启动 解决exit后卡空行/需手动^C/参数误判问题
# 优化移除命令行日志重定向完全依赖Java LogUtils输出日志、保留终端交互、增强异常处理
cd "$(dirname "${BASH_SOURCE[0]}")" || { echo "目录切换失败"; exit 1; }
BASE_DIR=$(cd .. && pwd)
LOG_DIR="$BASE_DIR/logs"
MAIN_LOG="$LOG_DIR/main.log"
# 1. 前置准备创建日志目录仅给Java LogUtils用脚本不再写日志
mkdir -p "$LOG_DIR" || { echo "日志目录创建失败"; exit 1; }
# 2. 编译校验
BUILD_SH="$BASE_DIR/bash/build_class.sh"
if [ ! -f "$BUILD_SH" ]; then
echo "编译脚本不存在:$BUILD_SH"
exit 1
fi
bash "$BUILD_SH" || { echo "编译失败退出"; exit 1; }
# 3. 类路径配置(指定完整包名主类)
CLASSPATH="$BASE_DIR/runtime"
[ -d "$BASE_DIR/libs" ] && CLASSPATH="$CLASSPATH:$BASE_DIR/libs/*"
MAIN_CLASS="cc.winboll.Main"
# 4. JVM优化配置适配Termux低内存环境
export _JAVA_OPTIONS="-Xmx128m -Xms64m -Dfile.encoding=UTF-8"
STOP_SIGNAL=0
JAVA_PID=0
# 5. 信号捕获:优雅停机+终端重置
on_exit() {
STOP_SIGNAL=1
echo -e "\n⚠ 收到停止信号,正在优雅停机..."
# 向Java进程发送中断信号
if [ $JAVA_PID -ne 0 ]; then
kill -INT $JAVA_PID 2>/dev/null
sleep 1
kill -9 $JAVA_PID 2>/dev/null
fi
stty sane
echo -e "✅ 服务已停止Java日志文件$MAIN_LOG"
exit 1
}
trap 'on_exit' SIGINT SIGTERM SIGABRT SIGSEGV SIGILL
# 6. 启动服务核心修改移除所有日志重定向stdout/stderr直接走终端
stty -echoctl # 屏蔽^C视觉印记
echo -e "🚀 服务启动中输入help查指令输入exit优雅停机"
echo -e "📝 Java日志输出路径$MAIN_LOG\n"
# 关键无任何重定向让Java的LogUtils负责写日志终端保留完整交互能力
java -cp "$CLASSPATH" "$MAIN_CLASS" -v -log:INFO