From 5031e016953f8646eae81497d246736ea0c27a07 Mon Sep 17 00:00:00 2001 From: haotian <2421912570@qq.com> Date: Tue, 29 Jul 2025 11:26:23 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BD=BF=E7=94=A8systemctl=E6=B7=BB=E5=8A=A0?= =?UTF-8?q?=E8=87=AA=E5=90=AF=E5=8A=A8=E8=84=9A=E6=9C=AC=E6=94=AF=E6=8C=81?= =?UTF-8?q?,=E6=9C=8D=E5=8A=A1=E5=90=8D=E4=B8=BAkangda=5Fwebsocket,=20kang?= =?UTF-8?q?da=5Fsync=5Frobot?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- kangda_sync_robot.service | 12 ++++++++++++ kangda_websocket.service | 12 ++++++++++++ run_sync_robot.py | 0 start_sync_robot.sh | 21 ++++++++++++++++++++- start_websocket.sh | 22 +++++++++++++++++++++- 测试Ocr.py | 30 ++++++++++++++++++++++++++++++ 6 files changed, 95 insertions(+), 2 deletions(-) create mode 100644 kangda_sync_robot.service create mode 100644 kangda_websocket.service mode change 100644 => 100755 run_sync_robot.py mode change 100644 => 100755 start_sync_robot.sh mode change 100644 => 100755 start_websocket.sh create mode 100644 测试Ocr.py diff --git a/kangda_sync_robot.service b/kangda_sync_robot.service new file mode 100644 index 0000000..60efa94 --- /dev/null +++ b/kangda_sync_robot.service @@ -0,0 +1,12 @@ +[Unit] +Description=My Custom Startup Script + +[Service] +User=admin-root +# 这里确保自己对 这个脚本有执行权限。 +ExecStart=/home/admin-root/haotian/康达瑞贝斯/康达后台项目/start_sync_robot.sh +Restart=on-failure +WorkingDirectory=/home/admin-root/ + +[Install] +WantedBy=multi-user.target diff --git a/kangda_websocket.service b/kangda_websocket.service new file mode 100644 index 0000000..8d69e6c --- /dev/null +++ b/kangda_websocket.service @@ -0,0 +1,12 @@ +[Unit] +Description=My Custom Startup Script + +[Service] +User=admin-root +# 这里确保自己对 这个脚本有执行权限。 +ExecStart=/home/admin-root/haotian/康达瑞贝斯/康达后台项目/start_websocket.sh +Restart=on-failure +WorkingDirectory=/home/admin-root/ + +[Install] +WantedBy=multi-user.target diff --git a/run_sync_robot.py b/run_sync_robot.py old mode 100644 new mode 100755 diff --git a/start_sync_robot.sh b/start_sync_robot.sh old mode 100644 new mode 100755 index 61c2916..7820209 --- a/start_sync_robot.sh +++ b/start_sync_robot.sh @@ -1,5 +1,23 @@ #! /bin/bash +__conda_setup="$('/home/admin-root/miniconda3/bin/conda' 'shell.bash' 'hook' 2> /dev/null)" +if [ $? -eq 0 ]; then + eval "$__conda_setup" +else + if [ -f "/home/admin-root/miniconda3/etc/profile.d/conda.sh" ]; then + . "/home/admin-root/miniconda3/etc/profile.d/conda.sh" + else + export PATH="/home/pro/miniconda3/bin:$PATH" + fi +fi +unset __conda_setup + + +conda activate ocr + +cd /home/admin-root/haotian/康达瑞贝斯/康达后台项目 + + LOG_DIR="logs/robot" mkdir -p $LOG_DIR @@ -14,7 +32,8 @@ if pgrep -f "run_sync_robot.py" > /dev/null; then exit 1 fi -nohup python run_sync_robot.py > "$LOG_FILE" 2>&1 & +# nohup python run_sync_robot.py > "$LOG_FILE" 2>&1 & +nohup python run_sync_robot.py > "$LOG_FILE" 2>&1 # 保存进程id echo $! > "$LOG_DIR/robot.pid" diff --git a/start_websocket.sh b/start_websocket.sh old mode 100644 new mode 100755 index a18da3a..ade38cb --- a/start_websocket.sh +++ b/start_websocket.sh @@ -1,5 +1,22 @@ #!/bin/bash +__conda_setup="$('/home/admin-root/miniconda3/bin/conda' 'shell.bash' 'hook' 2> /dev/null)" +if [ $? -eq 0 ]; then + eval "$__conda_setup" +else + if [ -f "/home/admin-root/miniconda3/etc/profile.d/conda.sh" ]; then + . "/home/admin-root/miniconda3/etc/profile.d/conda.sh" + else + export PATH="/home/pro/miniconda3/bin:$PATH" + fi +fi +unset __conda_setup + + +conda activate ocr + +cd /home/admin-root/haotian/康达瑞贝斯/康达后台项目 + # 创建日志目录 LOG_DIR="logs/websocket" mkdir -p $LOG_DIR @@ -14,7 +31,10 @@ if pgrep -f "run_websocket.py" > /dev/null; then fi # 在后台运行程序并将输出重定向到日志文件 -nohup python run_websocket.py > "$LOG_FILE" 2>&1 & +# nohup python run_websocket.py > "$LOG_FILE" 2>&1 & + +# 使用systemctl控制运行 +nohup python run_websocket.py > "$LOG_FILE" 2>&1 # 保存进程ID echo $! > "$LOG_DIR/websocket.pid" diff --git a/测试Ocr.py b/测试Ocr.py new file mode 100644 index 0000000..a2039fb --- /dev/null +++ b/测试Ocr.py @@ -0,0 +1,30 @@ + +import os +from app.util.baiduOcr import BadiduOcr +from app.util.kangda import Kangda + + + +baiduOcr = BadiduOcr() +kangda = Kangda() + +file_path = '/home/admin-root/haotian/康达瑞贝斯/康达后台项目/imagesOcr' + +image_path = [os.path.join(file_path, t) for t in os.listdir(file_path)] + +for image in image_path: + result = baiduOcr.image_inference(image) + value, conf = baiduOcr.parse_result(result) + print("-"*100) + print("image: ", image) + print("value:", value) + print("conf:", conf) + status = None + if len(value) > 0 and len(value) < 3: + status = kangda.parse_value(value) + print("status:", status, status.value if status else 0) + + + + +