diff --git a/SABnzbd.py b/SABnzbd.py index 9f5dca2..c98a4fc 100755 --- a/SABnzbd.py +++ b/SABnzbd.py @@ -1321,7 +1321,7 @@ def main(): rc = win32event.WaitForMultipleObjects((sabnzbd.WIN_SERVICE.hWaitStop, sabnzbd.WIN_SERVICE.overlapped.hEvent), 0, 3000) if rc == win32event.WAIT_OBJECT_0: - sabnzbd.save_state() + sabnzbd.save_state(flag=True) logging.info('Leaving SABnzbd') sabnzbd.SABSTOP = True return diff --git a/sabnzbd/__init__.py b/sabnzbd/__init__.py index 4599a23..95d94c3 100644 --- a/sabnzbd/__init__.py +++ b/sabnzbd/__init__.py @@ -140,7 +140,7 @@ def sig_handler(signum = None, frame = None): if type(signum) != type(None): logging.warning(Ta('warn-signal@1'), signum) try: - save_state() + save_state(flag=True) finally: SABSTOP = True os._exit(0) @@ -220,6 +220,13 @@ def initialize(pause_downloader = False, clean_up = False, evalSched=False, repa if check_repair_request(): repair = 2 pause_downloader = True + else: + # Check crash detection file + if load_admin(TERM_FLAG_FILE, remove=True): + repair = 2 + + # Set crash detection file + save_admin(1, TERM_FLAG_FILE) ### ### Initialize threads @@ -333,7 +340,7 @@ def halt(): pass ## Save State ## - save_state() + save_state(flag=True) # The Scheduler cannot be stopped when the stop was scheduled. # Since all warm-restarts have been removed, it's not longer @@ -405,7 +412,7 @@ def add_url(url, pp=None, script=None, cat=None, priority=None, nzbname=None): URLGrabber.do.add(url, future_nzo) -def save_state(): +def save_state(flag=False): ArticleCache.do.flush_articles() nzbqueue.save() BPSMeter.do.save() @@ -413,6 +420,9 @@ def save_state(): Bookmarks.do.save() DirScanner.do.save() PostProcessor.do.save() + if flag: + # Remove crash detector + load_admin(TERM_FLAG_FILE, remove=True) def pause_all(): global PAUSED_ALL diff --git a/sabnzbd/constants.py b/sabnzbd/constants.py index f9bb1e8..11a5a67 100644 --- a/sabnzbd/constants.py +++ b/sabnzbd/constants.py @@ -57,6 +57,7 @@ POSTPROC_QUEUE_FILE_NAME = 'postproc%s.sab' % POSTPROC_QUEUE_VERSION RSS_FILE_NAME = 'rss_data.sab' BOOKMARK_FILE_NAME = 'bookmarks.sab' SCAN_FILE_NAME = 'watched_data.sab' +TERM_FLAG_FILE = 'running.sab' JOB_ADMIN = '__ADMIN__' ATTRIB_FILE = 'SABnzbd_attrib' REPAIR_REQUEST = 'repair-all.sab'