diff --git a/selfdrive/updated.py b/selfdrive/updated.py index bb665180ed..cca3d1b69c 100755 --- a/selfdrive/updated.py +++ b/selfdrive/updated.py @@ -76,12 +76,12 @@ class WaitTimeHelper: self.ready_event.set() -def wait_between_updates(ready_event): +def wait_between_updates(ready_event, t=60*10): ready_event.clear() if SHORT: ready_event.wait(timeout=10) else: - ready_event.wait(timeout=60 * 10) + ready_event.wait(timeout=t) def link(src, dest): @@ -341,50 +341,52 @@ def main(): time.sleep(30) wait_helper = WaitTimeHelper() - while True: + while not wait_helper.shutdown: update_failed_count += 1 + + # Check for internet every 30s time_wrong = datetime.datetime.utcnow().year < 2019 ping_failed = subprocess.call(["ping", "-W", "4", "-c", "1", "8.8.8.8"]) + if ping_failed or time_wrong: + wait_between_updates(wait_helper.ready_event, t=30) + continue - # Wait until we have a valid datetime to initialize the overlay - if not (ping_failed or time_wrong): - try: - # If the git directory has modifcations after we created the overlay - # we need to recreate the overlay - if overlay_init_done: - overlay_init_fn = os.path.join(BASEDIR, ".overlay_init") - git_dir_path = os.path.join(BASEDIR, ".git") - new_files = run(["find", git_dir_path, "-newer", overlay_init_fn]) - - if len(new_files.splitlines()): - cloudlog.info(".git directory changed, recreating overlay") - overlay_init_done = False - - if not overlay_init_done: - init_ovfs() - overlay_init_done = True - - if params.get("IsOffroad") == b"1": - attempt_update() - update_failed_count = 0 - else: - cloudlog.info("not running updater, openpilot running") - - except subprocess.CalledProcessError as e: - cloudlog.event( - "update process failed", - cmd=e.cmd, - output=e.output, - returncode=e.returncode - ) - overlay_init_done = False - except Exception: - cloudlog.exception("uncaught updated exception, shouldn't happen") + # Attempt an update + try: + # If the git directory has modifcations after we created the overlay + # we need to recreate the overlay + if overlay_init_done: + overlay_init_fn = os.path.join(BASEDIR, ".overlay_init") + git_dir_path = os.path.join(BASEDIR, ".git") + new_files = run(["find", git_dir_path, "-newer", overlay_init_fn]) + + if len(new_files.splitlines()): + cloudlog.info(".git directory changed, recreating overlay") + overlay_init_done = False + + if not overlay_init_done: + init_ovfs() + overlay_init_done = True + + if params.get("IsOffroad") == b"1": + attempt_update() + update_failed_count = 0 + else: + cloudlog.info("not running updater, openpilot running") + + except subprocess.CalledProcessError as e: + cloudlog.event( + "update process failed", + cmd=e.cmd, + output=e.output, + returncode=e.returncode + ) + overlay_init_done = False + except Exception: + cloudlog.exception("uncaught updated exception, shouldn't happen") params.put("UpdateFailedCount", str(update_failed_count)) wait_between_updates(wait_helper.ready_event) - if wait_helper.shutdown: - break # We've been signaled to shut down dismount_ovfs()