QDAirPortBackend0122/mock.sh
2026-01-22 13:19:47 +08:00

93 lines
1.7 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
# Mock服务管理脚本
# 用法: ./mock.sh {start|stop|restart|status}
# 项目路径
TOOLS_DIR="./tools"
LOGS_DIR="./logs"
# 确保日志目录存在
mkdir -p "$LOGS_DIR"
# 服务列表
SERVICES=(
"mock_airport.py"
"mock_traffic_light.py"
"mock_unmanned_vehicle.py"
)
# 启动服务
start() {
echo "启动mock服务..."
cd "$TOOLS_DIR" || exit 1
for service in "${SERVICES[@]}"; do
if pgrep -f "$service" > /dev/null; then
echo " $service 已在运行"
else
# 各个mock服务已经有自己的日志管理不需要重定向输出
nohup python3 "$service" > /dev/null 2>&1 &
echo " $service 已启动"
fi
done
cd - > /dev/null
echo "所有mock服务启动完成"
}
# 停止服务
stop() {
echo "停止mock服务..."
for service in "${SERVICES[@]}"; do
if pkill -f "$service"; then
echo " $service 已停止"
else
echo " $service 未运行"
fi
done
echo "所有mock服务停止完成"
}
# 重启服务
restart() {
stop
sleep 2
start
}
# 检查服务状态
status() {
echo "检查mock服务状态..."
for service in "${SERVICES[@]}"; do
if pgrep -f "$service" > /dev/null; then
echo " $service: 运行中"
else
echo " $service: 已停止"
fi
done
}
# 根据参数执行相应操作
case "$1" in
start)
start
;;
stop)
stop
;;
restart)
restart
;;
status)
status
;;
*)
echo "用法: $0 {start|stop|restart|status}"
exit 1
;;
esac