Skip to content
Merged
Changes from 1 commit
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
53ba21d
update:前端-优化useTerm实现代码
4linuxfun Jan 17, 2025
2143ded
update:后端-简化scheduler任务,删除不必要代码
4linuxfun Jan 21, 2025
8daef2b
update:后端-scheduler完善
4linuxfun Jan 21, 2025
ae16ea1
update:后端-排除websocket权限验证
4linuxfun Jan 21, 2025
19e8bad
update:后端-实现“任务管理”模块功能
4linuxfun Jan 21, 2025
f2bf6d5
update:前端-重构usePagination
4linuxfun Jan 21, 2025
bf8f03c
update:前端-实现“执行任务”功能
4linuxfun Jan 21, 2025
c3c18b5
update:前端usePagination分页增加initialPageSize参数
4linuxfun Feb 10, 2025
7647004
update:前端-任务管理分页日志默认改为5
4linuxfun Feb 10, 2025
3544264
update:service.sh脚本增加部分逻辑判断
4linuxfun Feb 10, 2025
c75e188
update:前端usePagination补全async写法
4linuxfun Feb 11, 2025
9091c98
update:前端-补全缺失组件引用
4linuxfun Feb 11, 2025
ac23b67
fix:前端-修复主机选择关联带出bug
4linuxfun Feb 11, 2025
f9f57b1
fix:前端-修复翻页多选状态保持问题
4linuxfun Feb 12, 2025
e6a1b58
update:后端-更新config配置模式
4linuxfun Feb 12, 2025
23865ae
update:后端-修改yaml配置后的参数
4linuxfun Feb 12, 2025
e9c7183
update:后端-更新服务控制脚本
4linuxfun Feb 12, 2025
e493d2c
update:后端-修改redis过期时间
4linuxfun Feb 12, 2025
28ba966
update:后端-任务管理功能模块实现
4linuxfun Feb 12, 2025
0413a51
update:更新README.md
4linuxfun Feb 13, 2025
fd9180a
update:后端-增加生产环境配置模板
4linuxfun Feb 13, 2025
9cb6b59
update:其他
4linuxfun Feb 13, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
update:后端-更新服务控制脚本
  • Loading branch information
4linuxfun committed Feb 12, 2025
commit e9c7183b6cf5140d412c735ecfd9d5098ed66ff9
146 changes: 79 additions & 67 deletions service.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,82 +2,94 @@
# 生产、开发环境服务控制
# service.sh dev|pro start|stop|restart

start_fastapi() {
env=$1
if pgrep -f "gunicorn server.main:app" > /dev/null || pgrep -f "uvicorn server.main:app" > /dev/null; then
echo "FastAPI service is already running."
return 1
fi
echo "Starting FastAPI service..."
if [ "$env" = "pro" ]; then
echo "Running in production mode..."
nohup gunicorn server.main:app -b 127.0.0.1:8000 -w 4 -k uvicorn.workers.UvicornWorker >gunicorn.log 2>&1&
else
echo "Running in development mode..."
nohup uvicorn server.main:app --host 0.0.0.0 --port 8000 --reload --reload-exclude www > fastapi_dev.log 2>&1&
fi
# 获取脚本所在目录的绝对路径
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"

start_fastapi() {
env=$1
if pgrep -f "gunicorn server.main:app" > /dev/null || pgrep -f "uvicorn server.main:app" > /dev/null; then
echo "FastAPI service is already running."
return 1
fi

echo "Starting FastAPI service..."
cd "$SCRIPT_DIR"

if [ "$env" = "pro" ]; then
echo "Running in production mode..."
export ENV=production
nohup gunicorn server.main:app \
-b 127.0.0.1:8000 \
-w 4 \
-k uvicorn.workers.UvicornWorker \
> gunicorn.log 2>&1 &
else
echo "Running in development mode..."
export ENV=development
nohup python -m uvicorn server.main:app \
--host 0.0.0.0 --port 8000 \
--reload \
--reload-exclude www \
> fastapi_dev.log 2>&1 &
fi
}

stop_fastapi() {
env=$1
if ! pgrep -f "gunicorn server.main:app" > /dev/null && ! pgrep -f "uvicorn server.main:app" > /dev/null; then
echo "FastAPI service is not running."
return 1
fi
echo "Stopping FastAPI service..."
if [ "$env" = "pro" ]; then
echo "Running in production mode..."
pkill -f "gunicorn server.main:app"
else
echo "Running in development mode..."
pkill -f "uvicorn server.main:app"
fi
}

restart_fastapi() {
stop_fastapi "$1"
start_fastapi "$1"
}

start_rpyc() {
echo "Starting RPyc service..."
cd ./rpyc_scheduler && nohup python3.9 scheduler-server.py > ../rpyc_scheduler.log 2>&1&
cd ..
if ! pgrep -f "gunicorn server.main:app" > /dev/null && ! pgrep -f "uvicorn server.main:app" > /dev/null; then
echo "FastAPI service is not running."
return 1
fi
echo "Stopping FastAPI service..."
pkill -f "gunicorn.*server.main:app"
pkill -9 -f "python.*-m.*uvicorn.*server.main:app"
# 关闭所有相关的 Python 子进程
pkill -9 -f "multiprocessing-fork"
# 确保端口被释放
fuser -k 8000/tcp
}

stop_rpyc() {
echo "Stopping RPyc service..."
pkill -f "python scheduler-server.py"
start_scheduler() {
echo "Starting RPyC scheduler..."
cd "$SCRIPT_DIR"
if [ "$1" = "pro" ]; then
export ENV=production
else
export ENV=development
fi
export PYTHONPATH="$SCRIPT_DIR:$PYTHONPATH"
nohup python rpyc_scheduler/server.py > rpyc_scheduler.log 2>&1 &
}

restart_rpyc() {
stop_rpyc
start_rpyc
stop_scheduler() {
echo "Stopping RPyC scheduler..."
pkill -f "python.*server.py"
}

case "$2" in
start)
start_fastapi "$1"
start_rpyc
;;
stop)
stop_fastapi "$1"
stop_rpyc
;;
restart)
restart_fastapi "$1"
restart_rpyc
;;
*)
echo "Usage: $0 {dev|pro} {start|stop|restart}"
echo "Options:"
echo " dev Development environment"
echo " pro Production environment"
echo "Commands:"
echo " start Start services"
echo " stop Stop services"
echo " restart Restart services"
exit 1
;;
start)
start_fastapi "$1"
start_scheduler "$1"
;;
stop)
stop_fastapi
stop_scheduler
;;
restart)
stop_fastapi
stop_scheduler
sleep 2
start_fastapi "$1"
start_scheduler "$1"
;;
*)
echo "Usage: $0 {dev|pro} {start|stop|restart}"
echo "Options:"
echo " dev Development environment"
echo " pro Production environment"
echo "Commands:"
echo " start Start services"
echo " stop Stop services"
echo " restart Restart services"
exit 1
;;
esac