Browse Source

增加日志

nifangxu 1 tháng trước cách đây
mục cha
commit
4641213996
2 tập tin đã thay đổi với 112 bổ sung0 xóa
  1. 8 0
      core/alarm_plan.py
  2. 104 0
      run_LAS.py

+ 8 - 0
core/alarm_plan.py

@@ -353,6 +353,7 @@ class AlarmPlan:
 
                 if self.event_attr_.enter_ts_ == -1:
                     self.event_attr_.enter_ts_ = timestamp
+                    LOGINFO(f"detected target enter, plan_uuid: {self.plan_uuid_}")
                 else:
                     self.event_attr_.leave_ts_ = timestamp
 
@@ -370,6 +371,7 @@ class AlarmPlan:
                 self.event_attr_.reset()
                 LOGINFO(f"less than threshold_time, alarm_plan: {self.plan_uuid_}, event_type: {self.event_type_}")
                 return
+            LOGINFO(f"detected target leave, plan_uuid: {self.plan_uuid_}")
 
             # 构造事件
             # 入库
@@ -431,6 +433,7 @@ class AlarmPlan:
 
                 if self.event_attr_.enter_ts_ == -1:
                     self.event_attr_.enter_ts_ = timestamp
+                    LOGINFO(f"detected target enter, plan_uuid: {self.plan_uuid_}")
                 else:
                     self.event_attr_.leave_ts_ = timestamp
 
@@ -448,6 +451,7 @@ class AlarmPlan:
                 self.event_attr_.reset()
                 LOGINFO(f"less than threshold_time, alarm_plan: {self.plan_uuid_}, event_type: {self.event_type_}")
                 return
+            LOGINFO(f"detected target leave, plan_uuid: {self.plan_uuid_}")
 
             # 构造事件
             # 入库
@@ -509,6 +513,7 @@ class AlarmPlan:
 
                 if self.event_attr_.enter_ts_ == -1:
                     self.event_attr_.enter_ts_ = timestamp
+                    LOGINFO(f"detected target enter, plan_uuid: {self.plan_uuid_}")
                 else:
                     self.event_attr_.leave_ts_ = timestamp
 
@@ -526,6 +531,7 @@ class AlarmPlan:
                 self.event_attr_.reset()
                 LOGINFO(f"less than threshold_time, alarm_plan: {self.plan_uuid_}, event_type: {self.event_type_}")
                 return
+            LOGINFO(f"detected target leave, plan_uuid: {self.plan_uuid_}")
 
             # 构造事件
             # 入库
@@ -768,6 +774,7 @@ class AlarmPlan:
             timestamp = get_utc_time_s()
             if self.event_attr_.leave_ts_ == -1:
                 self.event_attr_.leave_ts_ = timestamp
+                LOGINFO(f"detected target leave, plan_uuid: {self.plan_uuid_}")
             else:
                 self.event_attr_.enter_ts_ = timestamp
 
@@ -785,6 +792,7 @@ class AlarmPlan:
                 self.event_attr_.reset()
                 LOGINFO(f"less than threshold_time, alarm_plan: {self.plan_uuid_}, event_type: {self.event_type_}")
                 return
+            LOGINFO(f"detected target enter, plan_uuid: {self.plan_uuid_}")
 
             # 构造事件
             # 入库

+ 104 - 0
run_LAS.py

@@ -0,0 +1,104 @@
+#!/usr/bin/env python3.9
+# -*- coding: utf-8 -*-
+
+import os
+import subprocess
+import sys
+
+# 配置
+GIT_URL = "http://43.137.10.199:3000/HFLN/LAS.git"
+LOCAL_PATH = "/platform/LAS/"
+GIT_USER = "nifangxu"
+GIT_PASS = "123456"
+
+
+def run_cmd(cmd, cwd=None):
+    """执行命令行并实时输出"""
+    print(f"[CMD] {cmd}")
+    process = subprocess.Popen(cmd, cwd=cwd, shell=True,
+                               stdout=subprocess.PIPE,
+                               stderr=subprocess.STDOUT,
+                               text=True)
+    for line in process.stdout:
+        print(line, end="")
+    process.wait()
+    if process.returncode != 0:
+        sys.exit(process.returncode)
+
+
+def update_repo():
+    """拉取或更新代码"""
+    if not os.path.exists(LOCAL_PATH):
+        print("本地仓库不存在,开始克隆...")
+        auth_url = GIT_URL.replace("http://", f"http://{GIT_USER}:{GIT_PASS}@")
+        run_cmd(f"git clone {auth_url} {LOCAL_PATH}")
+    else:
+        print("本地仓库已存在,开始更新...")
+        run_cmd("git reset --hard", cwd=LOCAL_PATH)
+        run_cmd("git pull", cwd=LOCAL_PATH)
+
+    # 设置权限
+    print("设置文件权限...")
+    run_cmd("dos2unix *", cwd=LOCAL_PATH)
+    run_cmd("chmod +x *.py", cwd=LOCAL_PATH)
+
+
+def check_repo():
+    """检查仓库目录是否存在"""
+    if not os.path.exists(LOCAL_PATH):
+        print("❌ 本地代码目录不存在,请先执行: python3 LAS-deploy.py update")
+        sys.exit(1)
+
+
+def start_service():
+    check_repo()
+    print("启动 LAS 服务...")
+    run_cmd("./start.py", cwd=LOCAL_PATH)
+
+
+def stop_service():
+    check_repo()
+    print("停止 LAS 服务...")
+    run_cmd("./stop.py", cwd=LOCAL_PATH)
+
+
+def restart_service():
+    check_repo()
+    print("重启 LAS 服务...")
+    run_cmd("./stop.py || true", cwd=LOCAL_PATH)
+    run_cmd("./start.py", cwd=LOCAL_PATH)
+
+
+def status_service():
+    check_repo()
+    print("查看 LAS 服务状态...")
+    run_cmd("./status.py", cwd=LOCAL_PATH)
+
+
+def main():
+    if len(sys.argv) < 2:
+        print("用法: python3 LAS-deploy.py [update|start|stop|restart|status]")
+        sys.exit(1)
+
+    action = sys.argv[1].lower()
+
+    if action == "update":
+        update_repo()
+    elif action == "start":
+        start_service()
+    elif action == "stop":
+        stop_service()
+    elif action == "restart":
+        restart_service()
+    elif action == "status":
+        status_service()
+    else:
+        print(f"未知参数: {action}")
+        print("可用参数: update | start | stop | restart | status")
+        sys.exit(1)
+
+    print(f"✅ 操作完成: {action}")
+
+
+if __name__ == "__main__":
+    main()