Skip to content

Commit

Permalink
add commands into debug.txt & check dmesg creation
Browse files Browse the repository at this point in the history
  • Loading branch information
nlef committed Mar 15, 2024
1 parent a9e9af7 commit f1d9e15
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
18 changes: 16 additions & 2 deletions bot/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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())

Expand Down
6 changes: 6 additions & 0 deletions scripts/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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..."

Expand Down Expand Up @@ -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
Expand Down

0 comments on commit f1d9e15

Please sign in to comment.