Skip to content

Commit

Permalink
Create function to validate current persist_logs state prior to updat…
Browse files Browse the repository at this point in the history
…es, then set to true if it is false with sane minimum auto-off delay
  • Loading branch information
SteveMicroNova committed Dec 9, 2024
1 parent 3e333e0 commit 80121fe
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 2 deletions.
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()
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>
</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

0 comments on commit 80121fe

Please sign in to comment.