From 4527bbf23298604783fc63a4165c3a57d9879d64 Mon Sep 17 00:00:00 2001
From: xyj <10908227994@qq.com>
Date: Fri, 1 Dec 2023 15:12:41 +0800
Subject: [PATCH] test
---
MQTT.py | 4 +-
__pycache__/tool.cpython-310.pyc | Bin 786 -> 825 bytes
api.py | 80 +---------------------
conf/mqtt.conf | 10 ---
push_stream.conf => conf/push_stream.conf | 2 +-
conf/test.conf | 0
conf/test2.conf | 10 ---
db/models/log_data_model.py | 2 +-
db/repository/lot_data_repository.py | 4 +-
exec_sh.sh | 1 -
lot_data.db | Bin 8192 -> 0 bytes
reload_conf.sh | 6 --
stop_push.sh | 2 +-
tool.py | 13 ++--
update.sh | 2 +-
15 files changed, 18 insertions(+), 118 deletions(-)
delete mode 100644 conf/mqtt.conf
rename push_stream.conf => conf/push_stream.conf (92%)
mode change 100755 => 100644 conf/test.conf
delete mode 100755 conf/test2.conf
delete mode 100644 exec_sh.sh
delete mode 100644 lot_data.db
delete mode 100644 reload_conf.sh
diff --git a/MQTT.py b/MQTT.py
index 899ab03..7eb9750 100644
--- a/MQTT.py
+++ b/MQTT.py
@@ -25,12 +25,12 @@ def on_message(client, userdata, msg):
close_stream()
elif data == "exec":
# 执行命令
- exec_sh()
+ exec_sh(msg)
elif data == "update":
# git更新项目和配置文件
update()
else:
- client.publish('conn_error', payload='No Such Type', qos=0)
+ client.publish('error', payload='No Such Type', qos=0)
if __name__ == '__main__':
diff --git a/__pycache__/tool.cpython-310.pyc b/__pycache__/tool.cpython-310.pyc
index a2d715a05f3f74304faa6d6992ccc4a1949ccd77..1b7110f8ce9cbe47290c0c4e59afa25677b1e4f5 100644
GIT binary patch
delta 109
zcmbQlwv&xFpO=@50SJoAGE+4s@~+_)*H6mK(@#n)&QO@RD~!>0vLK@tb54HAWP8S3
nZZU-9
td~wF)J|^YK{!A9!!U(C!9ZX#Sr_UhV
delta 59
zcmdnVHi?ZlpO=@50SLs?GEx~P@~&azop>aS(QdLdqZUg_VoBm;55` app.out 2>&1 & echo $! > app.pid'
- p = subprocess.Popen(start_cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
- out, err = p.communicate()
- return_code = p.returncode
- if return_code == 0:
- return BaseResponse(code=return_code, msg=out,
- data="http://192.168.1.27/live/test.live.mp4?secret=gqig2yFKkDpIMic1uWZY1L5MsIo0eflm")
- else:
- return BaseResponse(code=return_code, msg=err)
-
-
-@app.get("/stop")
-async def device_test2():
- ## 不管有没有都进行一个杀死
- cmd = 'lsof -t -i:554'
- p = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
- # 获取执行结果
- out, err = p.communicate()
- # 获取返回值
- return_code = p.returncode
- if out == b'':
- print("失败")
- else:
- pid = out
- cmd = f'kill -9 {pid}'
- print(pid)
- os.system(cmd)
- if return_code == 0:
- return BaseResponse(code=return_code, msg=out)
- return BaseResponse(code=return_code, msg=err)
-
-
-if __name__ == '__main__':
- uvicorn.run(app, host="127.0.0.1", port=8000)
diff --git a/conf/mqtt.conf b/conf/mqtt.conf
deleted file mode 100644
index dad5e0f..0000000
--- a/conf/mqtt.conf
+++ /dev/null
@@ -1,10 +0,0 @@
-[program:mqtt]
-directory=/home/lihai//PycharmProjects/pythonProject/lot_manager
-command=/home/lihai//anaconda3/envs/chatchat/bin/python MQTT.py
-user=lihai
-autostart=true
-autorestart=true
-redirect_stderr=true
-stopsignal=TERM
-stopasgroup=True
-priority=1
\ No newline at end of file
diff --git a/push_stream.conf b/conf/push_stream.conf
similarity index 92%
rename from push_stream.conf
rename to conf/push_stream.conf
index 2ac1028..8ec19dc 100644
--- a/push_stream.conf
+++ b/conf/push_stream.conf
@@ -2,7 +2,7 @@
directory=/home/lihai/PycharmProjects/pythonProject/lot_manager
command=/usr/bin/ffmpeg -rtsp_transport tcp -re -i rtsp://admin:123456@192.168.0.123:554/mpeg4 -c:v copy -c:a aac -preset ultrafast -r 20 -flvflags no_duration_filesize -f rtsp -rtsp_transport tcp rstp://127.0.0.1:554/live/test
user=lihai
-autostart=true
+autostart=false
autorestart=true
redirect_stderr=true
stopsignal=TERM
diff --git a/conf/test.conf b/conf/test.conf
old mode 100755
new mode 100644
diff --git a/conf/test2.conf b/conf/test2.conf
deleted file mode 100755
index 3dccdbc..0000000
--- a/conf/test2.conf
+++ /dev/null
@@ -1,10 +0,0 @@
-[program:test2]
-directory=/home/lihai/PycharmProjects/pythonProject/lot_manager
-command=/home/lihai/anaconda3/envs/chatchat/bin/python test.py
-user=lihai
-autostart=false
-autorestart=true
-restart_times=3
-redirect_stderr=true
-stopsignal=TERM
-stopasgroup=True
diff --git a/db/models/log_data_model.py b/db/models/log_data_model.py
index 4d1c177..f281a4a 100755
--- a/db/models/log_data_model.py
+++ b/db/models/log_data_model.py
@@ -4,6 +4,7 @@ from db.base import Base
class LOT_DATA(BaseModel):
+ create_time: int = Field(None, description='创建时间(时间戳) ')
wind_speed: float = Field(None, description='风速:(0到30)m/s ')
wind_direction: float = Field(None, description='风向:0~360°')
ambient_temperature: float = Field(None, description='环境温度:℃')
@@ -27,7 +28,6 @@ class LOT_DATA_MODEL(Base):
"""
__tablename__ = 'LOT_DATA_MODEL'
id = Column(Integer, primary_key=True, autoincrement=True, comment='ID')
- device_name = Column(String(50), comment='设备编号', default="0")
create_time = Column(Integer, comment="创建时间")
wind_speed = Column(Float, comment='风速:(0到30)m/s ')
wind_direction = Column(Float, comment='风向:0~360°')
diff --git a/db/repository/lot_data_repository.py b/db/repository/lot_data_repository.py
index 926ef86..603e322 100755
--- a/db/repository/lot_data_repository.py
+++ b/db/repository/lot_data_repository.py
@@ -5,9 +5,9 @@ from db.session import with_session
@with_session
-def add_kb_to_db(session, data: LOT_DATA, device_name: str):
+def add_kb_to_db(session, data: LOT_DATA):
# 创建知识库实例
- kb = LOT_DATA_MODEL(**data.__dict__, device_name=device_name, create_time=int(time.time()))
+ kb = LOT_DATA_MODEL(**data.__dict__, create_time=int(time.time()))
session.add(kb)
diff --git a/exec_sh.sh b/exec_sh.sh
deleted file mode 100644
index a9bf588..0000000
--- a/exec_sh.sh
+++ /dev/null
@@ -1 +0,0 @@
-#!/bin/bash
diff --git a/lot_data.db b/lot_data.db
deleted file mode 100644
index c438be439156e816fa3cee3018496cd3122fcb27..0000000000000000000000000000000000000000
GIT binary patch
literal 0
HcmV?d00001
literal 8192
zcmeI0UvASt5XSA0s&Y^i1P?)ihb0maQ&RqvpbCV9(-=~4lH$6R%8RwJH}OcZ*IKU&
zycYr2-~?QSYj6sjl+?IHp$C|eSKgWLoALVhX79hVKr%AsBBYXRDOVI#RbCRJD9T#4
zO4(Y3nr+I9B)iY@|HYcJIsR46Tx#`)l3f@`00|%gB!C2v01`j~NB{{S0VHri0w;ZS
zy{_x(*8@pMQ)Uevw`(|t+aGpKtC*E`Y}0T|;usyvB#oljAkB&fKG_{O=4;a?gP}tP
z2bOi8R5YI*gU8&6hKw8<_D;{Ro9&1CO!5SylDQHx=}+sd`~f20O=8A;^2!<-&RNX|
z!8{2(%Ih>70gI$7Sr{`xWh&UeVvvU5gZz{$9u*@VxjyiZ;4kT*Alz86Bq_`j6rwSm
zPV+g7$4_ArNQfr6l5m(VKh<0bIV8oy&dVN;{4{&T_7|dg^D^sc6BlW6fw^Y`a_^qK+c)eZ^42^eP4M-KKKnK=*SbpWXYG3}
z$u<~B00|%gB!C2v01`j~NB{{S0VIF~kib#`t@1VHMp-S!=}(kLEO`2@eebT;tM^N9
z>d!kJ(r#T^Y5$^MeY|mKZ#DbXn-8|%-)fas+COhU+q_(PvT^;kc1K%(VYJkh_LFn=
E-##|wLI3~&
diff --git a/reload_conf.sh b/reload_conf.sh
deleted file mode 100644
index 446b678..0000000
--- a/reload_conf.sh
+++ /dev/null
@@ -1,6 +0,0 @@
-#!/bin/bash
-#复制配置文件
-set -e
-cp -r reload_conf/*.conf /etc/supervisor/conf.d/
-# 重启所有配置
-supervisorctl reload
diff --git a/stop_push.sh b/stop_push.sh
index 3ddb7f6..19aa07e 100644
--- a/stop_push.sh
+++ b/stop_push.sh
@@ -1,4 +1,4 @@
#!/bin/bash
set -e
-supervisorctl stop test
+supervisorctl stop push_stream
diff --git a/tool.py b/tool.py
index 647c333..e7e61a0 100644
--- a/tool.py
+++ b/tool.py
@@ -1,18 +1,19 @@
+import json
import subprocess
def push_stream():
- print("启动推流")
- subprocess.Popen(['start_push.sh'], shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
+ subprocess.Popen(['/bin/bash start_push.sh'], shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
def close_stream():
- subprocess.Popen(['stop_push.sh'], shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
+ subprocess.Popen(['/bin/bash stop_push.sh'], shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
-def exec_sh():
- subprocess.Popen(['exec_sh.sh'], shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
+def exec_sh(msg):
+ cmd = json.loads(msg.payload.decode('utf-8'))["cmd"]
+ subprocess.Popen([cmd], shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
def update():
- subprocess.Popen(['update.sh'], shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
+ subprocess.Popen(['/bin/bash update.sh'], shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
diff --git a/update.sh b/update.sh
index 5da19c2..2861bc0 100644
--- a/update.sh
+++ b/update.sh
@@ -5,4 +5,4 @@ git pull origin master
# 配置文件复制到supervisor管理
cp -r conf/*.conf /etc/supervisor/conf.d/
# 更新配置文件
-supervisorctl reread
+supervisorctl update