From b25e598f393b7a67c2c838fc65e5a051f38e3d77 Mon Sep 17 00:00:00 2001 From: Kakune55 Date: Sun, 10 Dec 2023 16:43:45 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E4=BA=86=E5=90=AF=E5=8A=A8?= =?UTF-8?q?=E4=B8=8E=E5=81=9C=E6=AD=A2=E8=84=9A=E6=9C=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- start.sh | 12 ++++++++++++ stop.sh | 18 ++++++++++++++++++ 2 files changed, 30 insertions(+) create mode 100644 start.sh create mode 100644 stop.sh diff --git a/start.sh b/start.sh new file mode 100644 index 0000000..26434dc --- /dev/null +++ b/start.sh @@ -0,0 +1,12 @@ +#!/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 new file mode 100644 index 0000000..1d05932 --- /dev/null +++ b/stop.sh @@ -0,0 +1,18 @@ +#!/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 + +# 可以添加任何其他需要的停止逻辑