From 5aed29edacca47db82b89618b0939048b2b42fdb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=98=9F=E5=85=89-k?= <36470587+kxgx@users.noreply.github.com> Date: Mon, 13 Jan 2025 17:22:29 +0000 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0=20start.sh?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- bin/start.sh | 37 ++++++++----------------------------- 1 file changed, 8 insertions(+), 29 deletions(-) diff --git a/bin/start.sh b/bin/start.sh index c6bc512..c1c1119 100755 --- a/bin/start.sh +++ b/bin/start.sh @@ -3,34 +3,13 @@ f_name=main.py dir=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd ) logdir=${dir%/*} +screen_name="main_screen" -# 函数:杀死所有运行的main.py进程 -kill_process() { - pid=$(ps -ef | grep "$dir/$f_name" | grep -v grep | awk '{print $2}') - if [ ! -z "$pid" ]; then - for id in $pid; do - kill -9 $id - done - fi -} +# 查找并结束所有与指定screen_name相关的screen会话 +pids=$(screen -ls | grep $screen_name | awk -F '.' '{print $1}' | awk '{print $1}') +for pid in $pids; do + screen -S $pid -X quit +done -# 函数:启动main.py -start_process() { - nohup /usr/bin/python3 -u "$dir/$f_name" > "$logdir/log/info.log" 2>&1 & -} - -# 杀死所有已存在的main.py进程 -kill_process - -# 启动main.py -start_process - -# 无限循环,检查main.py是否在运行 -while true; do - sleep 180 # 每180秒检查一次 - pid=$(ps -ef | grep "$dir/$f_name" | grep -v grep | awk '{print $2}') - if [ -z "$pid" ]; then - echo "main.py is not running, restarting..." - start_process - fi -done \ No newline at end of file +# 创建一个新的screen会话并运行Python脚本 +screen -dmS $screen_name /usr/bin/python3 -u $dir/$f_name > $logdir/log/info.log 2>&1 \ No newline at end of file