系统更新指令
This commit is contained in:
@@ -1,4 +1,5 @@
|
|||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
|
import os
|
||||||
import subprocess
|
import subprocess
|
||||||
from loguru import logger
|
from loguru import logger
|
||||||
from typing import Dict, Any, List, Optional, Tuple
|
from typing import Dict, Any, List, Optional, Tuple
|
||||||
@@ -132,17 +133,23 @@ class SystemUpdaterPlugin(MessagePluginInterface):
|
|||||||
def _execute_system_update(self):
|
def _execute_system_update(self):
|
||||||
"""执行系统更新操作"""
|
"""执行系统更新操作"""
|
||||||
try:
|
try:
|
||||||
# 调用 restart.sh 脚本进行系统更新
|
# 使用相对路径调用 restart.sh 脚本
|
||||||
result = subprocess.run(
|
result = subprocess.run(
|
||||||
["/home/liuwei/wechatbot/WeChatRobot/restart.sh"], # 指定脚本的实际路径
|
["./restart.sh"], # 使用相对路径
|
||||||
check=True,
|
check=True,
|
||||||
stdout=subprocess.PIPE,
|
stdout=subprocess.PIPE,
|
||||||
stderr=subprocess.PIPE,
|
stderr=subprocess.PIPE,
|
||||||
|
cwd=os.path.join(os.path.dirname(__file__)) # 确保在当前目录执行
|
||||||
)
|
)
|
||||||
|
|
||||||
|
# 打印执行结果
|
||||||
logger.info(f"更新命令执行成功: {result.stdout.decode()}")
|
logger.info(f"更新命令执行成功: {result.stdout.decode()}")
|
||||||
|
|
||||||
except subprocess.CalledProcessError as e:
|
except subprocess.CalledProcessError as e:
|
||||||
|
# 如果 subprocess 执行出错,输出 stderr 信息
|
||||||
logger.error(f"执行更新命令时出错: {e.stderr.decode()}")
|
logger.error(f"执行更新命令时出错: {e.stderr.decode()}")
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
|
# 捕获其他异常
|
||||||
logger.error(f"系统更新失败: {str(e)}")
|
logger.error(f"系统更新失败: {str(e)}")
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user