mirror of
https://github.com/firestar5683/StarPilot.git
synced 2026-11-29 00:03:57 +08:00
Restore Save Me cleanup in Galaxy
This commit is contained in:
@@ -2327,6 +2327,9 @@ def make_server(*, port=8082, host='127.0.0.1', monitor=None, owner=None, crashe
|
||||
return
|
||||
result = software_owner().action(payload['action'], payload,
|
||||
authorized=lambda: self.settings_session() == identity)
|
||||
if payload['action'] == 'save-me':
|
||||
self.json(200, result)
|
||||
return
|
||||
result = {**(software_source if software_source is not None else SoftwareStatus()).snapshot(), 'operations': result}
|
||||
except SoftwareOperationError as error:
|
||||
if self.settings_session() == identity:
|
||||
|
||||
@@ -20,6 +20,7 @@ from openpilot.common.params import Params
|
||||
from openpilot.common.vendor_manifest import validate_revision
|
||||
from openpilot.starpilot.galaxy.software_status import SoftwareStatus, SoftwareUnavailable
|
||||
from openpilot.starpilot.saved_source import read_saved
|
||||
from openpilot.starpilot.software import save_me
|
||||
from openpilot.starpilot.software.update_control import UpdaterControlError
|
||||
from openpilot.starpilot.software.preferences import AUTOMATIC_DOWNLOADS, automatic_downloads
|
||||
from openpilot.starpilot.software.auto_install import DEFAULT_CRON, InstallSettings, cron_fields, next_restart
|
||||
@@ -506,15 +507,41 @@ class SoftwareOperations:
|
||||
raise SoftwareOperationError(str(error), 409) from error
|
||||
return self.snapshot()
|
||||
|
||||
def _save_me(self, payload: dict, authorized: Callable[[], bool]) -> dict:
|
||||
if set(payload) != {"action", "confirmation"} or payload["confirmation"] != save_me.CONFIRMATION:
|
||||
raise SoftwareOperationError(f"Type {save_me.CONFIRMATION} to run Save Me", 400)
|
||||
with self.lock:
|
||||
if not authorized():
|
||||
raise SoftwareOperationError("Session expired", 403)
|
||||
if not save_me.available():
|
||||
raise SoftwareOperationError("Save Me is unavailable on this device", 503)
|
||||
if self._param("UpdaterState") not in (None, "idle") or self.request is not None and self.request.get("state") == "pending":
|
||||
raise SoftwareOperationError("Wait for the software operation to finish before running Save Me", 409)
|
||||
if any(self._flag(key) is not False for key in ("DoUninstall", "DoShutdown", "DoReboot")):
|
||||
raise SoftwareOperationError("A device restart, shutdown or reset is already pending", 409)
|
||||
if (self.refresh is not None and self.refresh() is not True) or not self._parked():
|
||||
raise SoftwareOperationError("Park the vehicle before running Save Me", 409)
|
||||
if not authorized():
|
||||
raise SoftwareOperationError("Session expired", 403)
|
||||
try:
|
||||
save_me.request()
|
||||
except FileExistsError:
|
||||
raise SoftwareOperationError("Save Me is already pending", 409) from None
|
||||
except OSError:
|
||||
raise SoftwareOperationError("Could not start Save Me", 503) from None
|
||||
return {"resetRequested": True}
|
||||
|
||||
def action(self, action: str, payload: object, *, authorized: Callable[[], bool]) -> dict:
|
||||
if (type(payload) is not dict or type(action) is not str or
|
||||
action not in ("check", "download", "select", "install", "preferences", "install-preferences", "update", "fast", "rollback",
|
||||
"versions", "version", "download-version")):
|
||||
"versions", "version", "download-version", "save-me")):
|
||||
raise SoftwareOperationError("Invalid software action", 400)
|
||||
assert isinstance(payload, dict)
|
||||
payload = dict(payload)
|
||||
if payload.get("action") != action or any(type(key) is not str for key in payload):
|
||||
raise SoftwareOperationError("Invalid software action", 400)
|
||||
if action == 'save-me':
|
||||
return self._save_me(payload, authorized)
|
||||
if action == 'preferences':
|
||||
return self._preferences(payload, authorized)
|
||||
if action == 'install-preferences':
|
||||
|
||||
@@ -20,6 +20,7 @@ const assert = require('node:assert/strict')
|
||||
else if (path.endsWith('/recovery/preview')) data = {intent:'defaults',question:'Reset one saved setting to default?'}
|
||||
else if (path.endsWith('/recovery/confirm')) data = {saved:true,applied:['setting']}
|
||||
else if (path.endsWith('/recordings/action')) data = {deleted:2}
|
||||
else if (path.endsWith('/software/action')) data = {resetRequested:true}
|
||||
else return route.fulfill({status:404,json:{error:'Unexpected endpoint'}})
|
||||
return route.fulfill({json:data})
|
||||
})
|
||||
@@ -39,7 +40,7 @@ const assert = require('node:assert/strict')
|
||||
await summary.click()
|
||||
assert.equal(await card.evaluate(element=>element.open),false)
|
||||
await summary.click()
|
||||
assert.equal(await card.locator('.gx-maintenance__content').count(),2)
|
||||
assert.equal(await card.locator('.gx-maintenance__content').count(),3)
|
||||
assert.equal(await card.locator('.gx-card').count(),0)
|
||||
assert.equal(await card.getByText(/Vehicle not identified|Ready/).count(),0)
|
||||
assert.equal(await card.getByRole('button',{name:/Search/}).count(),0)
|
||||
@@ -48,7 +49,7 @@ const assert = require('node:assert/strict')
|
||||
await page.evaluate(theme=>document.documentElement.dataset.theme=theme,theme)
|
||||
assert.equal(await page.evaluate(()=>document.documentElement.scrollWidth>innerWidth),false)
|
||||
const actions = card.locator('.gx-maintenance__content .gx-actions > button')
|
||||
assert.equal(await actions.count(),4)
|
||||
assert.equal(await actions.count(),5)
|
||||
assert(await actions.evaluateAll(buttons=>buttons.every(button=>{
|
||||
const rect=button.getBoundingClientRect()
|
||||
return rect.left>=0 && rect.right<=innerWidth
|
||||
@@ -74,6 +75,27 @@ const assert = require('node:assert/strict')
|
||||
await page.getByText('2 driving routes deleted.',{exact:true}).waitFor()
|
||||
const deletion = mutations.find(item=>item.path.endsWith('/recordings/action'))
|
||||
assert.deepEqual(deletion.body,{action:'delete-all',confirmed:true,includePreserved:true})
|
||||
await page.setViewportSize({width:320,height:850})
|
||||
const saveMe = card.getByRole('button',{name:'Save Me',exact:true})
|
||||
assert(await saveMe.evaluate(button=>button.classList.contains('gx-btn--danger')))
|
||||
await saveMe.click()
|
||||
const dialog = page.getByRole('alertdialog',{name:'Erase StarPilot data?'})
|
||||
const submit = dialog.getByRole('button',{name:'Erase data and restart'})
|
||||
const input = dialog.getByLabel('Type ERASE STARPILOT DATA to continue')
|
||||
assert(await submit.isDisabled())
|
||||
await input.fill('erase starpilot data')
|
||||
assert(await submit.isDisabled())
|
||||
await input.fill('ERASE STARPILOT DATA')
|
||||
assert(await submit.isEnabled())
|
||||
assert(!mutations.some(item=>item.path.endsWith('/software/action')))
|
||||
await dialog.getByRole('button',{name:'Cancel'}).click()
|
||||
await saveMe.click()
|
||||
assert.equal(await input.inputValue(),'')
|
||||
await input.fill('ERASE STARPILOT DATA')
|
||||
await submit.click()
|
||||
await page.getByText(/Save Me requested/).waitFor()
|
||||
assert.deepEqual(mutations.filter(item=>item.path.endsWith('/software/action')).map(item=>item.body),
|
||||
[{action:'save-me',confirmation:'ERASE STARPILOT DATA'}])
|
||||
assert.deepEqual(errors,[])
|
||||
console.log('Unified maintenance layout, download/restore, toggle resets and deletion confirmation passed.')
|
||||
} finally { await browser.close() }
|
||||
|
||||
@@ -7,6 +7,7 @@ import subprocess
|
||||
import tempfile
|
||||
import threading
|
||||
import unittest
|
||||
from unittest.mock import patch
|
||||
|
||||
from openpilot.common.params import Params
|
||||
from openpilot.starpilot.galaxy.access import GalaxyAccessOwner
|
||||
@@ -15,6 +16,7 @@ from openpilot.starpilot.galaxy.server import make_remote_server, make_server
|
||||
from openpilot.starpilot.galaxy.software_operations import SoftwareOperations
|
||||
from openpilot.starpilot.galaxy.software_status import SoftwareStatus
|
||||
from openpilot.starpilot.galaxy.tests.test_software_operations import FakeProcess
|
||||
from openpilot.starpilot.software import save_me
|
||||
from openpilot.starpilot.software.auto_install import InstallSettings
|
||||
|
||||
|
||||
@@ -133,3 +135,27 @@ class SoftwareHttpTest(unittest.TestCase):
|
||||
self.assertEqual(self.request('/api/software/action', payload=payload, remote=True, cookie=self.remote_cookie)[0], 409)
|
||||
self.assertFalse(Path(self.params.get_param_path('UpdaterAutomaticDownloads')).exists())
|
||||
self.assertEqual(self.process.sent, [])
|
||||
|
||||
def test_save_me_queues_once_over_local_or_remote_when_parked(self):
|
||||
path = '/api/software/action'
|
||||
payload = {'action': 'save-me', 'confirmation': save_me.CONFIRMATION}
|
||||
with tempfile.TemporaryDirectory() as root, patch.object(save_me, 'available', return_value=True), \
|
||||
patch.object(save_me, 'REQUEST', Path(root) / 'request'):
|
||||
for remote, cookie in ((True, self.remote_cookie), (False, self.local_cookie)):
|
||||
self.assertEqual(self.request(path, payload=payload, remote=remote)[0], 401)
|
||||
self.assertEqual(self.request(path, payload=payload, remote=remote, cookie=cookie, origin='https://wrong.example')[0], 403)
|
||||
self.assertEqual(self.request(path, payload=payload | {'confirmation': 'yes'}, remote=remote, cookie=cookie)[0], 400)
|
||||
self.parked = False
|
||||
self.assertEqual(self.request(path, payload=payload, remote=remote, cookie=cookie)[0], 409)
|
||||
self.parked = True
|
||||
self.params.put('UpdaterState', 'updating...', block=True)
|
||||
self.assertEqual(self.request(path, payload=payload, remote=remote, cookie=cookie)[0], 409)
|
||||
self.params.put('UpdaterState', 'idle', block=True)
|
||||
self.assertFalse(save_me.REQUEST.exists())
|
||||
self.assertEqual(self.request(path, payload=payload, remote=remote, cookie=cookie)[:2], (200, {'resetRequested': True}))
|
||||
self.assertTrue(save_me.REQUEST.is_dir())
|
||||
self.assertEqual(self.request(path, payload=payload, remote=remote, cookie=cookie)[0], 409)
|
||||
save_me.clear_request()
|
||||
self.assertFalse(self.params.get_bool('DoUninstall'))
|
||||
self.assertFalse(self.params.get_bool('DoReboot'))
|
||||
self.assertEqual(self.process.sent, [])
|
||||
|
||||
@@ -0,0 +1,58 @@
|
||||
import { GxDialog } from "./dialog.js"
|
||||
import { GxNotice } from "./notice.js"
|
||||
import { MaintenanceGroup } from "./maintenance-group.js"
|
||||
import { requestJson } from "./startup.js"
|
||||
|
||||
const CONFIRMATION = "ERASE STARPILOT DATA"
|
||||
|
||||
export const SaveMe = {
|
||||
components: { GxDialog, GxNotice, MaintenanceGroup },
|
||||
props: { unauthorized: { type: Function, required: true } },
|
||||
data: () => ({ confirmOpen: false, typed: "", busy: false, requested: false, error: "" }),
|
||||
computed: { confirmed() { return this.typed === CONFIRMATION } },
|
||||
methods: {
|
||||
review() {
|
||||
this.typed = ""
|
||||
this.error = ""
|
||||
this.confirmOpen = true
|
||||
},
|
||||
async erase() {
|
||||
if (this.busy || this.requested || !this.confirmed) return
|
||||
this.busy = true
|
||||
this.error = ""
|
||||
try {
|
||||
const result = await requestJson("./api/software/action", {
|
||||
request: { method: "POST", headers: { "Content-Type": "application/json" },
|
||||
body: JSON.stringify({ action: "save-me", confirmation: this.typed }) },
|
||||
})
|
||||
if (result?.resetRequested !== true) throw new Error()
|
||||
this.requested = true
|
||||
this.confirmOpen = false
|
||||
} catch (error) {
|
||||
if (error.status === 401) this.unauthorized()
|
||||
else this.error = error.status ? error.message : "Connection lost. Check whether the comma is restarting before trying again."
|
||||
} finally { this.busy = false }
|
||||
},
|
||||
},
|
||||
template: `
|
||||
<div class="gx-maintenance__group gx-save-me">
|
||||
<MaintenanceGroup title="Danger zone" description="Erase StarPilot data and restart. Wi-Fi and installed software are kept.">
|
||||
<button type="button" class="gx-btn gx-btn--danger" :disabled="requested" @click="review">
|
||||
<i class="bi bi-exclamation-triangle-fill" aria-hidden="true"></i> Save Me
|
||||
</button>
|
||||
</MaintenanceGroup>
|
||||
<GxNotice v-if="requested" tone="danger">Save Me requested. Galaxy will disconnect during cleanup and restart.</GxNotice>
|
||||
<GxDialog v-if="confirmOpen" labelledby="gx-save-me-title" :alert="true" @close="!busy && (confirmOpen=false)">
|
||||
<h3 id="gx-save-me-title">Erase StarPilot data?</h3>
|
||||
<p>This permanently erases settings, calibration, driving routes, downloaded maps and models, themes, backups, and Galaxy pairing. Back up anything you need first.</p>
|
||||
<p>Park before continuing. Wi-Fi, AGNOS, and installed StarPilot stay in place. You will need to pair Galaxy again.</p>
|
||||
<label for="gx-erase-starpilot">Type ERASE STARPILOT DATA to continue</label>
|
||||
<input id="gx-erase-starpilot" class="gx-field" v-model="typed" autocomplete="off" autocapitalize="off" spellcheck="false" :disabled="busy">
|
||||
<GxNotice v-if="error" tone="danger">{{ error }}</GxNotice>
|
||||
<div class="gx-actions">
|
||||
<button type="button" class="gx-btn gx-btn--tonal" @click="confirmOpen=false" :disabled="busy">Cancel</button>
|
||||
<button type="button" class="gx-btn gx-btn--danger" @click="erase" :disabled="busy || !confirmed">Erase data and restart</button>
|
||||
</div>
|
||||
</GxDialog>
|
||||
</div>`,
|
||||
}
|
||||
@@ -1,12 +1,14 @@
|
||||
import { ToggleBackup } from './toggle-backup.js'
|
||||
import { RouteCleanup } from './route-cleanup.js'
|
||||
import { SaveMe } from './save-me.js'
|
||||
|
||||
export const SystemMaintenance = {
|
||||
components: { ToggleBackup, RouteCleanup },
|
||||
components: { ToggleBackup, RouteCleanup, SaveMe },
|
||||
props: { unauthorized: { type: Function, required: true } },
|
||||
template: `<details role="region" class="gx-card gx-maintenance" aria-label="Backup, reset and cleanup">
|
||||
<summary class="gx-section__header"><i class="bi bi-arrow-counterclockwise" aria-hidden="true"></i><span class="gx-section__title">Backup, Reset & Cleanup</span><i class="bi bi-chevron-down gx-maintenance__chevron" aria-hidden="true"></i></summary>
|
||||
<ToggleBackup :unauthorized="unauthorized" />
|
||||
<RouteCleanup :unauthorized="unauthorized" />
|
||||
<SaveMe :unauthorized="unauthorized" />
|
||||
</details>`,
|
||||
}
|
||||
|
||||
@@ -0,0 +1,95 @@
|
||||
"""StarPilot data reset, without invoking the OS factory reset."""
|
||||
|
||||
import os
|
||||
import shutil
|
||||
import stat
|
||||
import time
|
||||
from pathlib import Path
|
||||
|
||||
from openpilot.common.hardware import COMMA_HARDWARE
|
||||
|
||||
CONFIRMATION = "ERASE STARPILOT DATA"
|
||||
REQUEST = Path("/data/.starpilot-save-me")
|
||||
WIPE_PATHS = (
|
||||
"data/params",
|
||||
"cache/starpilot/params",
|
||||
"cache/params",
|
||||
"data/media/0/realdata",
|
||||
"data/media/0/realdata_HD",
|
||||
"data/media/0/realdata_konik",
|
||||
"data/models",
|
||||
"data/toggle_backups",
|
||||
"data/backups",
|
||||
"data/themes",
|
||||
"data/media/0/osm/offline",
|
||||
"cache/use_HD",
|
||||
"cache/use_konik",
|
||||
"data/starpilot",
|
||||
"data/media/0/starpilot",
|
||||
"data/starpilot-model-runtime",
|
||||
"data/galaxy",
|
||||
"data/galaxy-ble",
|
||||
"data/starport",
|
||||
"data/android_auto",
|
||||
"data/log",
|
||||
)
|
||||
|
||||
|
||||
def available() -> bool:
|
||||
return COMMA_HARDWARE and not os.environ.get("OPENPILOT_PREFIX") and os.environ.get("PARAMS_ROOT", "/data/params") == "/data/params"
|
||||
|
||||
|
||||
def request() -> None:
|
||||
REQUEST.mkdir(mode=0o700)
|
||||
|
||||
|
||||
def clear_request() -> None:
|
||||
try:
|
||||
REQUEST.rmdir()
|
||||
except FileNotFoundError:
|
||||
pass
|
||||
|
||||
|
||||
def take_request(*, parked: bool, started: bool) -> bool:
|
||||
try:
|
||||
marker = REQUEST.lstat()
|
||||
except FileNotFoundError:
|
||||
return False
|
||||
if not stat.S_ISDIR(marker.st_mode) or marker.st_uid != os.getuid() or stat.S_IMODE(marker.st_mode) != 0o700:
|
||||
return False
|
||||
fresh = 0 <= time.time() - marker.st_mtime <= 15
|
||||
if started or not fresh or parked:
|
||||
clear_request()
|
||||
return fresh and parked and not started
|
||||
|
||||
|
||||
def _remove(root: Path, relative: str, *, recursive: bool = True) -> None:
|
||||
# A symlink in a parent must not redirect deletion outside the intended tree.
|
||||
flags = os.O_RDONLY | os.O_DIRECTORY | os.O_NOFOLLOW
|
||||
fd = os.open(root, flags)
|
||||
try:
|
||||
*parents, name = Path(relative).parts
|
||||
for component in parents:
|
||||
next_fd = os.open(component, flags, dir_fd=fd)
|
||||
os.close(fd)
|
||||
fd = next_fd
|
||||
if recursive and stat.S_ISDIR(os.stat(name, dir_fd=fd, follow_symlinks=False).st_mode):
|
||||
shutil.rmtree(name, dir_fd=fd)
|
||||
else:
|
||||
os.unlink(name, dir_fd=fd)
|
||||
except FileNotFoundError:
|
||||
pass
|
||||
finally:
|
||||
os.close(fd)
|
||||
|
||||
|
||||
def wipe(root: Path = Path("/")) -> list[str]:
|
||||
# A regular reboot would otherwise install any already-staged update.
|
||||
_remove(root, "data/safe_staging/finalized/.overlay_consistent", recursive=False)
|
||||
failures = []
|
||||
for path in WIPE_PATHS:
|
||||
try:
|
||||
_remove(root, path)
|
||||
except OSError as error:
|
||||
failures.append(f"{path}: {error}")
|
||||
return failures
|
||||
@@ -0,0 +1,71 @@
|
||||
import os
|
||||
import time
|
||||
|
||||
import pytest
|
||||
|
||||
from openpilot.starpilot.software import save_me
|
||||
|
||||
|
||||
def test_legacy_and_current_paths_are_removed_but_wifi_and_software_survive(tmp_path):
|
||||
legacy = (
|
||||
"data/params", "cache/starpilot/params", "cache/params", "data/media/0/realdata",
|
||||
"data/media/0/realdata_HD", "data/media/0/realdata_konik", "data/models", "data/toggle_backups",
|
||||
"data/backups", "data/themes", "data/media/0/osm/offline", "cache/use_HD", "cache/use_konik",
|
||||
)
|
||||
removed = (*legacy, "data/starpilot", "data/media/0/starpilot", "data/galaxy", "data/starport")
|
||||
kept = ("data/etc/NetworkManager/system-connections/home.nmconnection", "data/etc/netplan/config",
|
||||
"data/openpilot/.git/HEAD", "data/safe_staging/finalized/program", "data/media/0/other", "VERSION")
|
||||
for path in removed:
|
||||
entry = tmp_path / path
|
||||
entry.mkdir(parents=True)
|
||||
(entry / "data").touch()
|
||||
for path in kept:
|
||||
entry = tmp_path / path
|
||||
entry.parent.mkdir(parents=True, exist_ok=True)
|
||||
entry.write_text("keep")
|
||||
marker = tmp_path / "data/safe_staging/finalized/.overlay_consistent"
|
||||
marker.touch()
|
||||
|
||||
assert save_me.wipe(tmp_path) == []
|
||||
assert not marker.exists()
|
||||
assert all(not (tmp_path / path).exists() for path in removed)
|
||||
assert all((tmp_path / path).read_text() == "keep" for path in kept)
|
||||
assert save_me.wipe(tmp_path) == []
|
||||
|
||||
|
||||
def test_symlinks_cannot_redirect_deletion(tmp_path):
|
||||
protected = tmp_path / "data/etc"
|
||||
protected.mkdir(parents=True)
|
||||
(protected / "wifi").touch()
|
||||
(tmp_path / "data/models").symlink_to(protected, target_is_directory=True)
|
||||
(tmp_path / "data/media").symlink_to(protected, target_is_directory=True)
|
||||
|
||||
assert save_me.wipe(tmp_path)
|
||||
assert not (tmp_path / "data/models").is_symlink()
|
||||
assert (protected / "wifi").is_file()
|
||||
|
||||
|
||||
def test_requests_expire_and_are_not_replayed_or_run_while_driving(tmp_path, monkeypatch):
|
||||
marker = tmp_path / "request"
|
||||
monkeypatch.setattr(save_me, "REQUEST", marker)
|
||||
save_me.request()
|
||||
assert not save_me.take_request(parked=False, started=False)
|
||||
assert save_me.take_request(parked=True, started=False)
|
||||
assert not save_me.take_request(parked=True, started=False)
|
||||
save_me.request()
|
||||
assert not save_me.take_request(parked=False, started=True)
|
||||
assert not marker.exists()
|
||||
save_me.request()
|
||||
old = time.time() - 60
|
||||
os.utime(marker, (old, old))
|
||||
assert not save_me.take_request(parked=True, started=False)
|
||||
assert not marker.exists()
|
||||
|
||||
|
||||
def test_cannot_wipe_if_staged_update_cannot_be_disarmed(tmp_path):
|
||||
params = tmp_path / "data/params"
|
||||
params.mkdir(parents=True)
|
||||
(tmp_path / "data/safe_staging/finalized/.overlay_consistent").mkdir(parents=True)
|
||||
with pytest.raises(OSError):
|
||||
save_me.wipe(tmp_path)
|
||||
assert params.is_dir()
|
||||
@@ -7,6 +7,7 @@ import time
|
||||
import traceback
|
||||
|
||||
from openpilot.starpilot.drive_state.owner import DriveStateOwner
|
||||
from openpilot.starpilot.drive_state.evidence import PhysicalSource
|
||||
from openpilot.starpilot.bookmark_state import clear_bookmark_checkpoint
|
||||
from openpilot.cereal import log
|
||||
import openpilot.cereal.messaging as messaging
|
||||
@@ -24,9 +25,15 @@ from openpilot.common.hardware.hw import Paths
|
||||
from openpilot.system import sentry
|
||||
from openpilot.starpilot.state_migration import prepare_manager_start
|
||||
from openpilot.starpilot.storage import starpilot_storage_root
|
||||
from openpilot.starpilot.software import save_me
|
||||
|
||||
|
||||
def manager_init() -> None:
|
||||
if save_me.available():
|
||||
try:
|
||||
save_me.clear_request()
|
||||
except OSError:
|
||||
cloudlog.exception("Could not clear stale Save Me request")
|
||||
params = Params()
|
||||
prepare_manager_start(params, starpilot_storage_root(), auto_migrate=True)
|
||||
if not PC:
|
||||
@@ -138,7 +145,7 @@ def manager_cleanup() -> None:
|
||||
cloudlog.info("everything is dead")
|
||||
|
||||
|
||||
def manager_thread() -> None:
|
||||
def manager_thread() -> bool:
|
||||
cloudlog.bind(daemon="manager")
|
||||
cloudlog.info("manager start")
|
||||
cloudlog.info({"environ": os.environ})
|
||||
@@ -157,6 +164,7 @@ def manager_thread() -> None:
|
||||
sm = messaging.SubMaster(['deviceState', 'carParams', 'pandaStates', 'modelV2', 'drivingModelData',
|
||||
'narrowRoadCameraState', 'wideRoadCameraState'], poll='deviceState')
|
||||
pm = messaging.PubMaster(['managerState'])
|
||||
save_me_vehicle = PhysicalSource(sm) if save_me.available() else None
|
||||
|
||||
params.put_bool("IsOffroad", True, block=True)
|
||||
ensure_running(managed_processes.values(), False, params=params, CP=sm['carParams'], not_run=ignore)
|
||||
@@ -218,7 +226,13 @@ def manager_thread() -> None:
|
||||
cloudlog.warning(f"Shutting down manager - {param} set")
|
||||
|
||||
if shutdown:
|
||||
break
|
||||
return False
|
||||
if save_me_vehicle is not None and save_me.REQUEST.exists():
|
||||
try:
|
||||
if save_me.take_request(parked=not started and save_me_vehicle.update_ready(params.get_bool("IsOffroad")), started=started):
|
||||
return True
|
||||
except OSError:
|
||||
cloudlog.exception("Could not consume Save Me request")
|
||||
|
||||
|
||||
def main() -> None:
|
||||
@@ -237,8 +251,9 @@ def main() -> None:
|
||||
# SystemExit on sigterm
|
||||
signal.signal(signal.SIGTERM, lambda signum, frame: sys.exit(1))
|
||||
|
||||
save_me_requested = False
|
||||
try:
|
||||
manager_thread()
|
||||
save_me_requested = manager_thread()
|
||||
except Exception:
|
||||
traceback.print_exc()
|
||||
cloudlog.exception("crash")
|
||||
@@ -252,6 +267,17 @@ def main() -> None:
|
||||
cloudlog.exception("Jetlink shutdown handoff failed")
|
||||
manager_cleanup()
|
||||
|
||||
if save_me_requested:
|
||||
try:
|
||||
for issue in save_me.wipe():
|
||||
cloudlog.error("Save Me: %s", issue)
|
||||
except OSError:
|
||||
cloudlog.exception("Save Me could not prepare cleanup")
|
||||
os.execv(sys.executable, [sys.executable, __file__])
|
||||
os.sync()
|
||||
HARDWARE.reboot()
|
||||
return
|
||||
|
||||
params = Params()
|
||||
if params.get_bool("DoUninstall"):
|
||||
cloudlog.warning("uninstalling")
|
||||
|
||||
+1
-1
@@ -1 +1 @@
|
||||
{"protected_inventory_sha256": "4e859e4ded50f18e1399226be9d8928b477c119b2d35607934a97495b690adb5", "schema_version": 1}
|
||||
{"protected_inventory_sha256": "3faf8b75ef6ca9a9aa228dbdffb3267f57fe596e100433bae2d403a33ca0ceb9", "schema_version": 1}
|
||||
|
||||
Reference in New Issue
Block a user