Files
jsowell-charger-web/bin/sh/app-prd.sh
2025-03-11 08:53:34 +08:00

95 lines
2.8 KiB
Bash
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
# 声明应用的名称和使用的端口号
APP_NAME=jsowell-admin.jar
PORT=8080 # 假设应用绑定到这个端口
# 使用函数来显示脚本的使用方式,并退出脚本
usage() {
echo "Usage: sh app.sh [start|stop|restart|status]"
exit 1
}
# 检查应用是否已经在运行
is_exist(){
# 使用 lsof 命令查找使用指定端口的进程ID这里应该是 lsof 的拼写错误,应为 lsof 或 lsof 的替代品如 netstat、ss
pid=$(lsof -t -i :$PORT)
if [ -z "$pid" ]; then
# 如果 pid 为空,表示没有找到对应的进程,返回 1
return 1
else
# 如果找到了进程,返回 0
return 0
fi
}
# 启动应用的函数
start(){
# 检查应用是否已经在运行
is_exist
if [ $? -eq 0 ]; then
# 如果应用已经在运行,则输出提示信息
echo "${APP_NAME} is already running on port $PORT."
else
# 如果应用没有运行,则启动应用,并将输出重定向到 nobup.log 文件
# 注意nohup 应该是 nohup 的拼写错误
echo "jsowell-admin.jar 正在启动..."
nohup java -Xms12g -Xmx12g -XX:+UseG1GC -jar /opt/app/spring/jar/jsowell-admin.jar --spring.profiles.active=prd >/dev/null 2>&1 &
echo "jsowell-admin.jar 启动完成..."
fi
}
# 停止应用的函数
stop(){
# 检查应用是否在运行
is_exist
if [ $? -eq 0 ]; then
# 如果应用在运行,则强制终止该进程
kill -9 $pid
# 输出停止应用的提示信息
echo "Stopped ${APP_NAME} running on port $PORT."
echo "jsowell-admin.jar已停止..."
else
# 如果应用没有运行,则输出提示信息
echo "${APP_NAME} is not running on port $PORT."
fi
}
# 检查应用状态的函数
status(){
# 检查应用是否在运行
is_exist
if [ $? -eq 0 ]; then
# 如果应用在运行则输出应用的运行状态和进程ID
echo "${APP_NAME} is running on port $PORT. Pid is $pid"
else
# 如果应用没有运行,则输出提示信息
echo "${APP_NAME} is NOT running on port $PORT."
fi
}
# 重启应用的函数
restart(){
# 停止应用
stop
# 启动应用
start
}
# 根据传入的参数执行相应的操作
case "$1" in
"start")
start # 启动应用
;;
"stop")
stop # 停止应用
;;
"status")
status # 检查应用状态
;;
"restart")
restart # 重启应用
;;
*)
usage # 如果参数不正确,则显示使用方式
;;
esac