diff --git a/SickBeard.py b/SickBeard.py index 96c7d793..f34033cf 100755 --- a/SickBeard.py +++ b/SickBeard.py @@ -19,6 +19,7 @@ # Check needed software dependencies to nudge users to fix their setup from __future__ import with_statement +import functools import sys import shutil @@ -311,9 +312,7 @@ def main(): sickbeard.CFG = ConfigObj(sickbeard.CONFIG_FILE) - myDB = db.DBConnection() - - CUR_DB_VERSION = myDB.checkDBVersion() + CUR_DB_VERSION = db.DBConnection().checkDBVersion() if CUR_DB_VERSION > 0: if CUR_DB_VERSION < MIN_DB_VERSION: @@ -327,16 +326,20 @@ def main(): MAX_DB_VERSION) + ").\n" + \ "If you have used other forks of SB, your database may be unusable due to their modifications.") - if sickbeard.DAEMON: + # Initialize the config and our threads + sickbeard.initialize(consoleLogging=consoleLogging) + + sickbeard.showList = [] + + if sickbeard.DAEMON and not sickbeard.restarted: daemonize() # Use this PID for everything sickbeard.PID = os.getpid() - # Initialize the config and our threads - sickbeard.initialize(consoleLogging=consoleLogging) - - sickbeard.showList = [] + # Build from the DB to start with + logger.log(u"Loading initial show list") + loadShowsFromDB() if forcedPort: logger.log(u"Forcing web server to port " + str(forcedPort)) @@ -374,11 +377,14 @@ def main(): } # init tornado - webserveInit.initWebServer(options) - - # Build from the DB to start with - logger.log(u"Loading initial show list") - loadShowsFromDB() + try: + webserveInit.initWebServer(options) + except IOError: + logger.log(u"Unable to start web server, is something else running on port %d?" % startPort, logger.ERROR) + if sickbeard.LAUNCH_BROWSER and not sickbeard.DAEMON: + logger.log(u"Launching browser and exiting", logger.ERROR) + sickbeard.launchBrowser(startPort) + sys.exit() def startup(): # Fire up all our threads @@ -392,20 +398,15 @@ def main(): if forceUpdate or sickbeard.UPDATE_SHOWS_ON_START: sickbeard.showUpdateScheduler.action.run(force=True) # @UndefinedVariable + # If we restarted then unset the restarted flag if sickbeard.restarted: sickbeard.restarted = False # create ioloop io_loop = IOLoop.current() - # init startup tasks io_loop.add_timeout(datetime.timedelta(seconds=5), startup) - # autoreload. - tornado.autoreload.add_reload_hook(autoreload_shutdown) - if sickbeard.AUTO_UPDATE: - tornado.autoreload.start(io_loop) - io_loop.start() sickbeard.saveAndShutdown() diff --git a/gui/slick/js/restart.js b/gui/slick/js/restart.js index 9ff51ab0..293ca3b3 100644 --- a/gui/slick/js/restart.js +++ b/gui/slick/js/restart.js @@ -16,39 +16,7 @@ var timeout_id; var restarted = ''; var num_restart_waits = 0; -function is_alive() { - timeout_id = 0; - $.get(is_alive_url, function(data) { - - // if it's still initalizing then just wait and try again - if (data.msg == 'nope') { - $('#shut_down_loading').hide(); - $('#shut_down_success').show(); - $('#restart_message').show(); - setTimeout('is_alive()', 1000); - } else { - // if this is before we've even shut down then just try again later - if (restarted == '' || data.restarted == restarted) { - restarted = data.restarted; - setTimeout('is_alive()', 1000); - - // if we're ready to go then redirect to new url - } else { - $('#restart_loading').hide(); - $('#restart_success').show(); - $('#refresh_message').show(); - window.location = sb_base_url+'/home/'; - } - } - }, 'jsonp'); -} - -$(document).ready(function() -{ - - is_alive(); - - $(document).ajaxError(function(e, jqxhr, settings, exception) { +function restartHandler() { num_restart_waits += 1; $('#shut_down_loading').hide(); @@ -68,6 +36,14 @@ $(document).ready(function() }, 3000); setTimeout("window.location = sb_base_url+'/home/'", 5000); } + } else { + timeout_id = 1; + setTimeout(function(){ + $('#restart_loading').hide(); + $('#restart_success').show(); + $('#refresh_message').show(); + }, 3000); + setTimeout("window.location = sb_base_url+'/home/'", 5000); } // if it is taking forever just give up @@ -80,6 +56,32 @@ $(document).ready(function() if (timeout_id == 0) timeout_id = setTimeout('is_alive()', 1000); - }); +} +function is_alive() { + timeout_id = 0; + + $.get(is_alive_url, function(data) { + + // if it's still initalizing then just wait and try again + if (data.msg == 'nope') { + $('#shut_down_loading').hide(); + $('#shut_down_success').show(); + $('#restart_message').show(); + setTimeout('is_alive()', 1000); + } else if (data.restarted == 'True') { + restartHandler(); + } else { + // if this is before we've even shut down then just try again later + if (restarted == '' || data.restarted == restarted) { + restarted = data.restarted; + setTimeout(is_alive, 1000); + } + } + }, 'jsonp'); +} + +$(document).ready(function() +{ + is_alive(); }); diff --git a/sickbeard/notifiers/trakt.py b/sickbeard/notifiers/trakt.py index 4cac11f9..d16f63c3 100644 --- a/sickbeard/notifiers/trakt.py +++ b/sickbeard/notifiers/trakt.py @@ -73,7 +73,7 @@ class TraktNotifier: """ data = TraktCall("account/test/%API%", api, username, password, {}) - if data["status"] == "success": + if data and data["status"] == "success": return True def _username(self): diff --git a/sickbeard/versionChecker.py b/sickbeard/versionChecker.py index 8936bc86..86fc2753 100644 --- a/sickbeard/versionChecker.py +++ b/sickbeard/versionChecker.py @@ -57,8 +57,11 @@ class CheckVersion(): if self.check_for_new_version(): if sickbeard.AUTO_UPDATE: logger.log(u"New update found for SickRage, starting auto-updater ...") + ui.notifications.message('New update found for SickRage, starting auto-updater') if sickbeard.versionCheckScheduler.action.update(): logger.log(u"Update was successful!") + ui.notifications.message('Update was successful') + threading.Timer(2, sickbeard.invoke_restart, [False]).start() def find_install_type(self): """ diff --git a/sickbeard/webserveInit.py b/sickbeard/webserveInit.py index c7c3c57f..7eb4906d 100644 --- a/sickbeard/webserveInit.py +++ b/sickbeard/webserveInit.py @@ -106,11 +106,8 @@ def initWebServer(options={}): logger.log(u"Starting SickRage on " + protocol + "://" + str(options['host']) + ":" + str( options['port']) + "/") - try: + if not sickbeard.restarted: server.listen(options['port'], options['host']) - except: - pass - def shutdown(): global server