Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Persist Logs during updates #1004

Merged
merged 1 commit into from
Dec 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# AmpliPi Software Releases

## 0.4.6
* System
* Automatically persist logs during (and for a short time after) updates

## 0.4.5
* Web App
* Ensure that abnormally-shaped album art is still horizontally centered
Expand Down
17 changes: 17 additions & 0 deletions amplipi/updater/asgi.py
Original file line number Diff line number Diff line change
Expand Up @@ -255,11 +255,27 @@ def save_upload_file(upload_file: UploadFile, destination: pathlib.Path) -> None
upload_file.file.close()


def persist_logs_during_update():
"""Used during system updates to ensure persist logs is activated and has a minimum delay"""
persist_data = get_log_persist_state()
existing_persist = persist_data.persist_logs
existing_delay = persist_data.auto_off_delay
# If persist logs is already on and has a larger delay, keep that delay; otherwise ensure it has our sane minimum for support
if existing_persist and (existing_delay > 3 or existing_delay == 0):
data = Persist_Logs(persist_logs=True, auto_off_delay=existing_delay)
toggle_persist_logs(data=data)
else:
# Three days is an arbitrary number, picked to ensure the next few days of usage post-update are captured for support cases
data = Persist_Logs(persist_logs=True, auto_off_delay=3)
toggle_persist_logs(data=data)


@router.post("/update/upload")
async def start_upload(file: UploadFile = File(...)):
""" Start a upload based update """
logger.info(file.filename)
try:
persist_logs_during_update()
# TODO: use a temp directory and pass it the installation
os.makedirs('web/uploads', exist_ok=True)
save_upload_file(file, pathlib.Path('web/uploads/update.tar.gz'))
Expand All @@ -285,6 +301,7 @@ async def download_update(info: ReleaseInfo):
""" Download the update """
logger.info(f'downloading update from: {info.url}')
try:
persist_logs_during_update()
SteveMicroNova marked this conversation as resolved.
Show resolved Hide resolved
os.makedirs('web/uploads', exist_ok=True)
download(info.url, 'web/uploads/update.tar.gz')
return 200
Expand Down
5 changes: 3 additions & 2 deletions amplipi/updater/static/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ <h1><span class="text-white">Ampli</span><span class="text-danger">Pi</span></h1
<a class="nav-link" id="manual-update-tab" data-toggle="tab" href="#manual-update" role="tab" aria-controls="manual-update" aria-selected="false">Custom Update</a>
</li>
<li class="nav-item">
<a class="nav-link" id="admin-settings-tab" data-toggle="tab" href="#admin-settings" role="tab" aria-controls="admin-settings" aria-selected="false">Admin Settings</a>
<a class="nav-link" id="admin-settings-tab" data-toggle="tab" href="#admin-settings" role="tab" aria-controls="admin-settings" aria-selected="false" onClick="getPersist();">Admin Settings</a>
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now that the state of that tab can be changed by updating, change the update method from window.onload to tab.onclick

</li>
<li class="nav-item">
<a class="nav-link" id="support-tunnel-tab" data-toggle="tab" href="#support-tunnel" role="tab" aria-controls="support-tunnel" aria-selected="false">Support Tunnel</a>
Expand Down Expand Up @@ -153,6 +153,8 @@ <h1><span class="text-white">Ampli</span><span class="text-danger">Pi</span></h1
const textbox = document.getElementById("persist-input");
checkbox.checked = data.persist_logs;
textbox.value = data.auto_off_delay;

return {"persist_logs": data.persist_logs, "auto_off_delay": data.auto_off_delay}
}

async function setPersist() {
Expand Down Expand Up @@ -190,7 +192,6 @@ <h1><span class="text-white">Ampli</span><span class="text-danger">Pi</span></h1
}, 1500);
}

window.onload = getPersist;
</script>

<div id="admin-settings-dialog">
Expand Down
Loading