Files
Jarvis_java/manage_service.sh
2025-12-14 15:43:00 +08:00

86 lines
2.3 KiB
Bash
Raw Permalink 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
# 物流服务管理脚本
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
cd "$SCRIPT_DIR"
PID_FILE="logistics_service.pid"
LOG_FILE="logistics_service.log"
case "$1" in
start)
echo "启动物流服务..."
if [ -f "$PID_FILE" ]; then
PID=$(cat "$PID_FILE")
if ps -p $PID > /dev/null 2>&1; then
echo "⚠️ 服务已在运行PID: $PID"
exit 1
else
rm -f "$PID_FILE"
fi
fi
./run_logistics.sh --background
;;
stop)
echo "停止物流服务..."
if [ ! -f "$PID_FILE" ]; then
echo "⚠️ PID 文件不存在,服务可能未运行"
exit 1
fi
PID=$(cat "$PID_FILE")
if ps -p $PID > /dev/null 2>&1; then
kill $PID
sleep 1
if ps -p $PID > /dev/null 2>&1; then
echo "强制停止服务..."
kill -9 $PID
fi
rm -f "$PID_FILE"
echo "✅ 服务已停止"
else
echo "⚠️ 进程不存在,清理 PID 文件"
rm -f "$PID_FILE"
fi
;;
restart)
echo "重启物流服务..."
$0 stop
sleep 2
$0 start
;;
status)
if [ -f "$PID_FILE" ]; then
PID=$(cat "$PID_FILE")
if ps -p $PID > /dev/null 2>&1; then
echo "✅ 服务正在运行"
echo "PID: $PID"
echo "进程信息:"
ps -p $PID -o pid,ppid,cmd,etime
else
echo "❌ 服务未运行PID 文件存在但进程不存在)"
rm -f "$PID_FILE"
fi
else
echo "❌ 服务未运行"
fi
;;
logs)
if [ -f "$LOG_FILE" ]; then
tail -f "$LOG_FILE"
else
echo "日志文件不存在: $LOG_FILE"
fi
;;
*)
echo "用法: $0 {start|stop|restart|status|logs}"
echo ""
echo "命令说明:"
echo " start - 启动服务(后台运行)"
echo " stop - 停止服务"
echo " restart - 重启服务"
echo " status - 查看服务状态"
echo " logs - 查看实时日志"
exit 1
;;
esac