Browse Source

Add optional web-watchdog to the watchdog.

tags/0.7.7
ShyPike 13 years ago
parent
commit
9c314532c0
  1. 15
      SABnzbd.py
  2. 1
      sabnzbd/cfg.py
  3. 8
      sabnzbd/interface.py
  4. 15
      sabnzbd/newsunpack.py

15
SABnzbd.py

@ -686,12 +686,12 @@ def attach_server(host, port, cert=None, key=None, chain=None):
adapter.subscribe()
def is_sabnzbd_running(url):
def is_sabnzbd_running(url, timeout=None):
""" Return True when there's already a SABnzbd instance running.
"""
try:
url = '%s&mode=version' % (url)
ver = sabnzbd.newsunpack.get_from_url(url)
ver = sabnzbd.newsunpack.get_from_url(url, timeout=timeout)
return bool(ver and re.search(r'\d+\.\d+\.', ver))
except:
return False
@ -1563,7 +1563,7 @@ def main():
add_local(f)
# Have to keep this running, otherwise logging will terminate
timer = 0
timer = timer5 = 0
while not sabnzbd.SABSTOP:
if sabnzbd.WIN_SERVICE:
rc = win32event.WaitForMultipleObjects((sabnzbd.WIN_SERVICE.hWaitStop,
@ -1603,6 +1603,15 @@ def main():
if sabnzbd.WIN_SERVICE and mail:
mail.send('active')
if timer5 > 9:
### 5 minute polling tasks
timer5 = 0
if sabnzbd.cfg.web_watchdog() and not is_sabnzbd_running('%s/api?tickleme=1' % sabnzbd.BROWSER_URL, 120):
autorestarted = True
cherrypy.engine.execv = True
else:
timer5 += 1
else:
timer += 1

1
sabnzbd/cfg.py

@ -255,6 +255,7 @@ marker_file = OptionStr('misc', 'nomedia_marker', '')
wait_ext_drive = OptionNumber('misc', 'wait_ext_drive', 5, 1, 60)
history_limit = OptionNumber('misc', 'history_limit', 50, 0)
show_sysload = OptionNumber('misc', 'show_sysload', 2, 0, 2)
web_watchdog = OptionBool('misc', 'web_watchdog', False)
#------------------------------------------------------------------------------
# Set root folders for Folder config-items

8
sabnzbd/interface.py

@ -415,8 +415,9 @@ class MainPage(object):
def api(self, **kwargs):
"""Handler for API over http, with explicit authentication parameters
"""
logging.debug('API-call from %s [%s] %s', cherrypy.request.remote.ip, \
cherrypy.request.headers.get('User-Agent', '??'), kwargs)
if not kwargs.get('tickleme') or not cfg.web_watchdog():
logging.debug('API-call from %s [%s] %s', cherrypy.request.remote.ip, \
cherrypy.request.headers.get('User-Agent', '??'), kwargs)
if kwargs.get('mode', '') not in ('version', 'auth'):
msg = check_apikey(kwargs)
if msg: return msg
@ -1214,7 +1215,8 @@ SPECIAL_BOOL_LIST = \
'queue_complete_pers', 'api_warnings', 'allow_64bit_tools', 'par2_multicore',
'never_repair', 'allow_streaming', 'ignore_unrar_dates', 'rss_filenames', 'news_items',
'osx_menu', 'osx_speed', 'win_menu', 'uniconfig', 'use_pickle', 'allow_incomplete_nzb',
'randomize_server_ip', 'no_ipv6', 'keep_awake', 'overwrite_files', 'empty_postproc'
'randomize_server_ip', 'no_ipv6', 'keep_awake', 'overwrite_files', 'empty_postproc',
'web_watchdog'
)
SPECIAL_VALUE_LIST = \
( 'size_limit', 'folder_max_length', 'fsys_type', 'movie_rename_limit', 'nomedia_marker',

15
sabnzbd/newsunpack.py

@ -1526,7 +1526,10 @@ def list2cmdline(lst):
#------------------------------------------------------------------------------
# Work-around for the failure of Python2.5 on Windows to support IPV6 with HTTPS
def get_from_url(url):
def get_from_url(url, timeout=None):
""" Retrieve URL and return content
`timeout` sets non-standard timeout and skips when on Windows
"""
if 'https:' in url and sabnzbd.WIN32 and sys.version_info < (2,6) and sabnzbd.newsunpack.CURL_COMMAND:
command = [sabnzbd.newsunpack.CURL_COMMAND, "-k", url]
stup, need_shell, command, creationflags = build_command(command)
@ -1538,6 +1541,12 @@ def get_from_url(url):
p.wait()
else:
import urllib2
s = urllib2.urlopen(url)
output = s.read()
try:
if timeout:
s = urllib2.urlopen(url, timeout=timeout)
else:
s = urllib2.urlopen(url)
output = s.read()
except:
output = None
return output

Loading…
Cancel
Save