diff --git a/app/sovran_systemsos_web/server.py b/app/sovran_systemsos_web/server.py index 037e6af..238e5c3 100644 --- a/app/sovran_systemsos_web/server.py +++ b/app/sovran_systemsos_web/server.py @@ -167,6 +167,15 @@ def _read_update_status() -> str: return "IDLE" +def _write_update_status(status: str): + """Write to the status file.""" + try: + with open(UPDATE_STATUS, "w") as f: + f.write(status) + except OSError: + pass + + def _read_log(offset: int = 0) -> tuple[str, int]: """Read the update log file from the given byte offset. Returns (new_text, new_offset).""" @@ -318,6 +327,14 @@ async def api_updates_run(): if status == "RUNNING": return {"ok": True, "status": "already_running"} + # Clear stale status and log BEFORE starting the unit + _write_update_status("RUNNING") + try: + with open(UPDATE_LOG, "w") as f: + f.write("") + except OSError: + pass + # Reset failed state if any await asyncio.create_subprocess_exec( "systemctl", "reset-failed", UPDATE_UNIT,