From 98ce0217269c774dd8deb55e359270f0d2c3f6ef Mon Sep 17 00:00:00 2001 From: Kakune55 Date: Tue, 21 May 2024 22:36:59 +0800 Subject: [PATCH] =?UTF-8?q?feat:=E6=B7=BB=E5=8A=A0=E4=BE=9D=E8=B5=96?= =?UTF-8?q?=E6=96=87=E4=BB=B6=20=E6=B7=BB=E5=8A=A0=E6=8E=A7=E5=88=B6?= =?UTF-8?q?=E8=84=9A=E6=9C=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app_control.sh | 46 ++++++++++++++++++++++++++++++++++++++++++++++ requirements.txt | 6 ++++++ start.sh | 12 ------------ stop.sh | 18 ------------------ 4 files changed, 52 insertions(+), 30 deletions(-) create mode 100644 app_control.sh create mode 100644 requirements.txt delete mode 100644 start.sh delete mode 100644 stop.sh diff --git a/app_control.sh b/app_control.sh new file mode 100644 index 0000000..0e1fc94 --- /dev/null +++ b/app_control.sh @@ -0,0 +1,46 @@ +#!/bin/bash + +VENV_DIR=".venv" +PYTHON_APP="main.py" + +start_app() { + source "$VENV_DIR/bin/activate" + nohup python3 $PYTHON_APP > output.log 2>&1 & + echo -e "\033[32m Application started! \033[0m" +} + +stop_app() { + pid=$(ps aux | grep $PYTHON_APP | grep -v grep | awk '{print $2}') + if [ -n "$pid" ]; then + kill $pid + echo -e "\033[32m Application ended! \033[0m" + else + echo -e "\033[31m Application not runing! \033[0m" + fi +} + +check_app_status() { + pid=$(ps aux | grep $PYTHON_APP | grep -v grep | awk '{print $2}') + if [ -n "$pid" ]; then + echo -e "PID:" $pid + echo -e "\033[32m Application runing! \033[0m" + else + echo -e "\033[31m Application not runing! \033[0m" + fi +} + +case "$1" in + start) + start_app + ;; + stop) + stop_app + ;; + status) + check_app_status + ;; + *) + echo -e "\033[33m Usage: $0 {start|stop|status}\033[0m" + exit 1 + ;; +esac diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..9c382d1 --- /dev/null +++ b/requirements.txt @@ -0,0 +1,6 @@ +pymysql +requests +flask +zhipuai +openai +flask_cors \ No newline at end of file diff --git a/start.sh b/start.sh deleted file mode 100644 index 26434dc..0000000 --- a/start.sh +++ /dev/null @@ -1,12 +0,0 @@ -#!/bin/bash - -# 定义要运行的Python文件 -PYTHON_APP="main.py" - -# 使用nohup命令启动Python程序,并将其输出重定向到日志文件 -nohup python3 $PYTHON_APP > output.log 2>&1 & - -# 打印消息,通知用户程序已启动 -echo "Python application started!" - -# 可以添加任何其他需要的启动逻辑 diff --git a/stop.sh b/stop.sh deleted file mode 100644 index 1d05932..0000000 --- a/stop.sh +++ /dev/null @@ -1,18 +0,0 @@ -#!/bin/bash - -# 定义要停止的Python文件 -PYTHON_APP="main.py" - -# 使用ps命令查找Python进程,并使用grep过滤出要停止的进程 -PID=$(ps -ef | grep $PYTHON_APP | grep -v grep | awk '{print $2}') - -# 检查是否找到了进程 -if [ -z "$PID" ]; then - echo "Python application is not running!" -else - # 使用kill命令停止进程 - kill $PID - echo "Python application stopped!" -fi - -# 可以添加任何其他需要的停止逻辑