Browse Source

Implement file flag to check whether SABnzbd's state was proiperly saved.

If not, do a repair on the next start up.
tags/0.6.0
ShyPike 15 years ago
parent
commit
62661987f1
  1. 2
      SABnzbd.py
  2. 16
      sabnzbd/__init__.py
  3. 1
      sabnzbd/constants.py

2
SABnzbd.py

@ -1321,7 +1321,7 @@ def main():
rc = win32event.WaitForMultipleObjects((sabnzbd.WIN_SERVICE.hWaitStop, rc = win32event.WaitForMultipleObjects((sabnzbd.WIN_SERVICE.hWaitStop,
sabnzbd.WIN_SERVICE.overlapped.hEvent), 0, 3000) sabnzbd.WIN_SERVICE.overlapped.hEvent), 0, 3000)
if rc == win32event.WAIT_OBJECT_0: if rc == win32event.WAIT_OBJECT_0:
sabnzbd.save_state() sabnzbd.save_state(flag=True)
logging.info('Leaving SABnzbd') logging.info('Leaving SABnzbd')
sabnzbd.SABSTOP = True sabnzbd.SABSTOP = True
return return

16
sabnzbd/__init__.py

@ -140,7 +140,7 @@ def sig_handler(signum = None, frame = None):
if type(signum) != type(None): if type(signum) != type(None):
logging.warning(Ta('warn-signal@1'), signum) logging.warning(Ta('warn-signal@1'), signum)
try: try:
save_state() save_state(flag=True)
finally: finally:
SABSTOP = True SABSTOP = True
os._exit(0) os._exit(0)
@ -220,6 +220,13 @@ def initialize(pause_downloader = False, clean_up = False, evalSched=False, repa
if check_repair_request(): if check_repair_request():
repair = 2 repair = 2
pause_downloader = True 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 ### Initialize threads
@ -333,7 +340,7 @@ def halt():
pass pass
## Save State ## ## Save State ##
save_state() save_state(flag=True)
# The Scheduler cannot be stopped when the stop was scheduled. # The Scheduler cannot be stopped when the stop was scheduled.
# Since all warm-restarts have been removed, it's not longer # 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) URLGrabber.do.add(url, future_nzo)
def save_state(): def save_state(flag=False):
ArticleCache.do.flush_articles() ArticleCache.do.flush_articles()
nzbqueue.save() nzbqueue.save()
BPSMeter.do.save() BPSMeter.do.save()
@ -413,6 +420,9 @@ def save_state():
Bookmarks.do.save() Bookmarks.do.save()
DirScanner.do.save() DirScanner.do.save()
PostProcessor.do.save() PostProcessor.do.save()
if flag:
# Remove crash detector
load_admin(TERM_FLAG_FILE, remove=True)
def pause_all(): def pause_all():
global PAUSED_ALL global PAUSED_ALL

1
sabnzbd/constants.py

@ -57,6 +57,7 @@ POSTPROC_QUEUE_FILE_NAME = 'postproc%s.sab' % POSTPROC_QUEUE_VERSION
RSS_FILE_NAME = 'rss_data.sab' RSS_FILE_NAME = 'rss_data.sab'
BOOKMARK_FILE_NAME = 'bookmarks.sab' BOOKMARK_FILE_NAME = 'bookmarks.sab'
SCAN_FILE_NAME = 'watched_data.sab' SCAN_FILE_NAME = 'watched_data.sab'
TERM_FLAG_FILE = 'running.sab'
JOB_ADMIN = '__ADMIN__' JOB_ADMIN = '__ADMIN__'
ATTRIB_FILE = 'SABnzbd_attrib' ATTRIB_FILE = 'SABnzbd_attrib'
REPAIR_REQUEST = 'repair-all.sab' REPAIR_REQUEST = 'repair-all.sab'

Loading…
Cancel
Save