This commit is contained in:
xyj 2023-12-05 09:14:18 +08:00
parent 8a7209e7b9
commit 5366686433
2 changed files with 3 additions and 3 deletions

View File

@ -23,7 +23,7 @@ class MQTT:
client.publish('success', payload='close_stream success', qos=0) client.publish('success', payload='close_stream success', qos=0)
elif data == "exec": elif data == "exec":
# 执行命令 # 执行命令
exec_sh(msg) exec_sh(msg, client)
client.publish('success', payload='exec_sh success', qos=0) client.publish('success', payload='exec_sh success', qos=0)
elif data == "update": elif data == "update":
# git更新项目和配置文件 # git更新项目和配置文件

View File

@ -15,14 +15,14 @@ def close_stream():
subprocess.Popen(['/bin/bash stop_push.sh'], shell=True) subprocess.Popen(['/bin/bash stop_push.sh'], shell=True)
def exec_sh(msg): def exec_sh(msg, client):
cmd = json.loads(msg.payload.decode('utf-8'))["data"] cmd = json.loads(msg.payload.decode('utf-8'))["data"]
if cmd == "supervisorctl stop __mqtt__": if cmd == "supervisorctl stop __mqtt__":
return return
p = subprocess.Popen([cmd], shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE) p = subprocess.Popen([cmd], shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
out, err = p.communicate() out, err = p.communicate()
output = out.decode('utf-8') output = out.decode('utf-8')
print(output) client.publish('success', payload=json.dumps(output, ensure_ascii=False), qos=0)
def update(): def update():