Files
gangyan/backend/start_local.sh

50 lines
1.4 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.

#!/bin/bash
# 启动 Java 后端。profile=yj。
# MySQL 33306 / Redis 等统一见同目录 application-local.yml与 scripts/backend-restart.sh 一致,勿再写 -D 数据源以免和 yml 冲突)。
set -euo pipefail
export JAVA_HOME=/usr/lib/jvm/java-11-openjdk-amd64
export PATH="$JAVA_HOME/bin:$PATH"
PROJECT_DIR=/opt/download/oss_files/gangyan-deploy/gangyan/backend
JAR_FILE="$PROJECT_DIR/chat_web_yj.jar"
LOCAL_CFG="$PROJECT_DIR/application-local.yml"
if [[ ! -f "$JAR_FILE" ]]; then
echo "Error: JAR file not found at $JAR_FILE"
exit 1
fi
pkill -f "chat_web_yj.jar" 2>/dev/null || true
sleep 2
# 日志目录logback 写 /opt/apps/...);非 root 启动时需可写
mkdir -p "$PROJECT_DIR/logs" /opt/apps/logs/chat-server-backend-cast 2>/dev/null || true
LOG_OUT="$PROJECT_DIR/nohup.out"
if ! ( umask 022; : >>"$LOG_OUT" ) 2>/dev/null; then
LOG_OUT="/tmp/chat_web_yj_nohup.log"
fi
EXTRA_JAVA=()
[[ -f "$LOCAL_CFG" ]] && EXTRA_JAVA=(-Dspring.config.additional-location="file:${LOCAL_CFG}")
nohup java \
-Djava.net.useSystemProxies=false \
-Dhttp.nonProxyHosts="localhost|127.*|[::1]|*.local" \
-Xms512m \
-Xmx2048m \
"${EXTRA_JAVA[@]}" \
-Dspring.profiles.active=yj \
-jar "$JAR_FILE" >>"$LOG_OUT" 2>&1 &
sleep 10
if pgrep -f "chat_web_yj.jar" > /dev/null; then
echo "OK PID $(pgrep -n -f 'java .*chat_web_yj\.jar' | head -1) log:$LOG_OUT"
else
tail -50 "$LOG_OUT" 2>/dev/null || true
exit 1
fi