spring-cloud/yudao-gateway/run.sh

72 lines
1.4 KiB
Bash
Raw Blame History

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

#!/bin/bash
# 定义应用的基本配置
APP_NAME="GatewayServerApplication"
JAR_FILE="yudao-gateway.jar"
PID_FILE="$APP_NAME.pid"
LOG_FILE="$APP_NAME.log"
# 指定Java环境变量如果需要的话
# JAVA_HOME=/usr/lib/jvm/java-1.8.0-openjdk-amd64
# export JAVA_HOME
# export PATH=$JAVA_HOME/bin:$PATH
# JVM运行参数
JAVA_OPTS="-Xms128m -Xmx128m"
# 启动函数
start() {
if [ -f $PID_FILE ]; then
echo "服务已经启动进程ID$(cat $PID_FILE)"
exit 1
fi
echo "启动服务..."
nohup java $JAVA_OPTS -jar $JAR_FILE > $LOG_FILE 2>&1 &
echo $! > $PID_FILE
echo "服务已启动进程ID$!"
}
# 停止函数
stop() {
if [ ! -f $PID_FILE ]; then
echo "服务未运行!"
exit 1
fi
PID=$(cat $PID_FILE)
echo "停止服务 (PID: $PID)..."
kill $PID
rm -f $PID_FILE
echo "服务已停止。"
}
# 重启函数
restart() {
stop
sleep 3 # 等待服务完全停止后稍作延迟再启动
start
}
# 解析命令行参数
case "$1" in
start)
start
;;
stop)
stop
;;
restart)
restart
;;
status)
if [ -f $PID_FILE ]; then
echo "服务正在运行进程ID$(cat $PID_FILE)"
else
echo "服务未运行。"
fi
;;
*)
echo "Usage: $0 {start|stop|restart|status}"
exit 1
esac
exit 0