From f1d9e1573168f8dfaddcc4c82dd2096af7fc1dab Mon Sep 17 00:00:00 2001 From: nlef <52351624+nlef@users.noreply.github.com> Date: Fri, 15 Mar 2024 22:28:45 +0300 Subject: [PATCH] add commands into debug.txt & check dmesg creation --- bot/main.py | 18 ++++++++++++++++-- scripts/install.sh | 6 ++++++ 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/bot/main.py b/bot/main.py index b7bd75a..0289ac5 100644 --- a/bot/main.py +++ b/bot/main.py @@ -350,7 +350,15 @@ def upload_logs(update: Update, _: CallbackContext) -> None: if Path(f"{configWrap.bot_config.log_path}/dmesg.txt").exists(): Path(f"{configWrap.bot_config.log_path}/dmesg.txt").unlink() - subprocess.run(f"dmesg -T > {configWrap.bot_config.log_path}/dmesg.txt", shell=True, executable="/bin/bash", check=False) + dmesg_res = subprocess.run(f"dmesg -T > {configWrap.bot_config.log_path}/dmesg.txt", shell=True, executable="/bin/bash", check=False, capture_output=True) + if dmesg_res.returncode != 0: + logger.warning("dmesg file creation error: %s %s", dmesg_res.stdout.decode("utf-8"), dmesg_res.stderr.decode("utf-8")) + update.effective_message.reply_text( + text=f'Dmesg log file creation error {dmesg_res.stderr.decode("utf-8")}', + disable_notification=notifier.silent_commands, + quote=True, + ) + return if Path(f"{configWrap.bot_config.log_path}/debug.txt").exists(): Path(f"{configWrap.bot_config.log_path}/debug.txt").unlink() @@ -368,12 +376,18 @@ def upload_logs(update: Update, _: CallbackContext) -> None: "ip --details --statistics link show dev can0", ] for command in commands: - subprocess.run(f"{command} >> {configWrap.bot_config.log_path}/debug.txt", shell=True, executable="/bin/bash", check=False) + subprocess.run( + f'echo >> {configWrap.bot_config.log_path}/debug.txt;echo "{command}" >> {configWrap.bot_config.log_path}/debug.txt;{command} >> {configWrap.bot_config.log_path}/debug.txt', + shell=True, + executable="/bin/bash", + check=False, + ) files = ["/boot/config.txt", "/boot/cmdline.txt", "/boot/armbianEnv.txt", "/boot/orangepiEnv.txt", "/boot/BoardEnv.txt", "/boot/env.txt"] with open(configWrap.bot_config.log_path + "/debug.txt", mode="a", encoding="utf-8") as debug_file: for file in files: if Path(file).exists(): + debug_file.write(f"\n{file}\n") with open(file, mode="r", encoding="utf-8") as file_obj: debug_file.writelines(file_obj.readlines()) diff --git a/scripts/install.sh b/scripts/install.sh index 171057c..cd10b46 100755 --- a/scripts/install.sh +++ b/scripts/install.sh @@ -131,6 +131,11 @@ install_packages() { sudo apt-get install --yes ${PKGLIST} } +fix_permissions()}{ + sudo echo "kernel.dmesg_restrict = 0" > /etc/sysctl.d/51-dmesg-restrict.conf + sudo sysctl kernel.dmesg_restrict=0 +} + create_virtualenv() { report_status "Installing python virtual environment..." @@ -196,6 +201,7 @@ install_instances(){ sudo systemctl stop moonraker-telegram-bot* status_msg "Installing dependencies" install_packages + fix_permissions create_virtualenv init_config_path