Files
AuthCenterConsoleApp/bash/start_winboll_in_termux_infolog.sh

57 lines
2.0 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. 编译校验核心修正匹配真实Main.class路径避免误判编译失败
BUILD_SH="$BASE_DIR/bash/build_class.sh"
if [ ! -f "$BUILD_SH" ]; then
echo "编译脚本不存在:$BUILD_SH"
exit 1
fi
bash "$BUILD_SH"
if [ $? -ne 0 ] && [ ! -f "$BASE_DIR/runtime/cc/winboll/Main.class" ]; then
echo "编译失败退出"; exit 1
fi
echo "✅ 编译校验通过"
# 3. 类路径+主类配置(核心修正:主类用完整包名,适配目录结构)
CLASSPATH="$BASE_DIR/runtime"
[ -d "$BASE_DIR/libs" ] && CLASSPATH="$CLASSPATH:$BASE_DIR/libs/*"
MAIN_CLASS="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 0
}
trap 'on_exit' SIGINT SIGTERM SIGABRT SIGSEGV SIGILL
# 6. 启动服务(无日志重定向,保留终端交互,屏蔽^C印记
stty -echoctl
echo -e "🚀 服务启动中输入help查指令输入exit优雅停机"
echo -e "📝 Java日志输出路径$MAIN_LOG\n"
# 启动核心命令
java -cp "$CLASSPATH" "$MAIN_CLASS" -v -log:INFO