diff --git a/RMS/StartCapture.py b/RMS/StartCapture.py index a7aeb68fb..ac6c6d6f4 100644 --- a/RMS/StartCapture.py +++ b/RMS/StartCapture.py @@ -909,7 +909,17 @@ def runCapture(config, duration=None, video_file=None, nodetect=False, detect_en # Standard mode: need to run it all just once # Continuous mode: if the program just got done with nighttime processing and needs to reboot elif (not config.continuous_capture) or (not daytime_mode_prev and config.reboot_after_processing): - break + + # Continuous mode: stop the capture before returning for the reboot. If the reboot + # fails, the main loop calls runCapture again - the old capture must not be left + # running, or two captures will run in parallel and save every frame twice, with the + # old one stamping a stale day/night suffix (it holds the previous daytime_mode) + if config.continuous_capture: + log.info('Ending capture before reboot...') + dropped_frames = bc.stopCapture() + log.info('Total number of late or dropped frames: ' + str(dropped_frames)) + + break ran_once = True @@ -1264,7 +1274,13 @@ def processIncompleteCaptures(config, upload_manager): # Reboot the computer (script needs sudo privileges, works only on Linux) try: - os.system('sudo shutdown -r now') + exit_status = os.system('sudo shutdown -r now') + + # os.system returns a wait status, not the exit code directly + if exit_status != 0: + log.error('Reboot command failed with exit code {}, ' + 'giving up on rebooting'.format(exit_status >> 8)) + break except Exception as e: log.debug('Rebooting failed with message:\n' + repr(e)) @@ -1292,7 +1308,7 @@ def processIncompleteCaptures(config, upload_manager): # If reboot didn't happen in continuous capture mode, reset so capture resumes normally if config.continuous_capture: - log.warning("Reboot failed after 4 hours of attempts, resuming capture") + log.warning("Reboot did not happen, resuming capture") ran_once = False