mirror of
https://github.com/moparisthebest/SickRage
synced 2024-12-12 19:12:26 -05:00
Moved Tornado IOLoop to main() to resolve shutdown issues plus we now use IOLoop to control checks for startup tasks and background commands.
This commit is contained in:
parent
20e2ae2f86
commit
af6cd334a0
30
SickBeard.py
30
SickBeard.py
@ -146,6 +146,12 @@ def daemonize():
|
|||||||
os.dup2(stderr.fileno(), sys.stderr.fileno())
|
os.dup2(stderr.fileno(), sys.stderr.fileno())
|
||||||
|
|
||||||
|
|
||||||
|
# background update every x seconds
|
||||||
|
def invoke_command():
|
||||||
|
if sickbeard.invoked_command:
|
||||||
|
sickbeard.invoked_command()
|
||||||
|
sickbeard.invoked_command = None
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
"""
|
"""
|
||||||
TV for me
|
TV for me
|
||||||
@ -361,16 +367,11 @@ def main():
|
|||||||
'https_key': sickbeard.HTTPS_KEY,
|
'https_key': sickbeard.HTTPS_KEY,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
def startup():
|
||||||
# Build from the DB to start with
|
# Build from the DB to start with
|
||||||
logger.log(u"Loading initial show list")
|
logger.log(u"Loading initial show list")
|
||||||
loadShowsFromDB()
|
loadShowsFromDB()
|
||||||
|
|
||||||
# start tornado thread
|
|
||||||
webserverInit(options).start()
|
|
||||||
|
|
||||||
# Fire up all our threads
|
|
||||||
sickbeard.start()
|
|
||||||
|
|
||||||
# Launch browser if we're supposed to
|
# Launch browser if we're supposed to
|
||||||
if sickbeard.LAUNCH_BROWSER and not noLaunch and not sickbeard.DAEMON:
|
if sickbeard.LAUNCH_BROWSER and not noLaunch and not sickbeard.DAEMON:
|
||||||
sickbeard.launchBrowser(startPort)
|
sickbeard.launchBrowser(startPort)
|
||||||
@ -379,18 +380,21 @@ def main():
|
|||||||
if forceUpdate or sickbeard.UPDATE_SHOWS_ON_START:
|
if forceUpdate or sickbeard.UPDATE_SHOWS_ON_START:
|
||||||
sickbeard.showUpdateScheduler.action.run(force=True) # @UndefinedVariable
|
sickbeard.showUpdateScheduler.action.run(force=True) # @UndefinedVariable
|
||||||
|
|
||||||
# Stay alive while my threads do the work
|
# init tornado
|
||||||
while (True):
|
sickbeard.WEBSERVER = webserverInit(options)
|
||||||
|
sickbeard.WEBSERVER.ioloop.add_timeout(datetime.timedelta(seconds=5), startup)
|
||||||
|
|
||||||
if sickbeard.invoked_command:
|
# Fire up all our threads
|
||||||
sickbeard.invoked_command()
|
sickbeard.start()
|
||||||
sickbeard.invoked_command = None
|
|
||||||
|
|
||||||
time.sleep(1)
|
# check for commands to be executed in the background
|
||||||
|
task = tornado.ioloop.PeriodicCallback(invoke_command, 1000)
|
||||||
|
task.start()
|
||||||
|
|
||||||
|
# start tornado
|
||||||
|
sickbeard.WEBSERVER.start()
|
||||||
return
|
return
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
if sys.hexversion >= 0x020600F0:
|
if sys.hexversion >= 0x020600F0:
|
||||||
freeze_support()
|
freeze_support()
|
||||||
|
@ -77,6 +77,7 @@ PIDFILE = ''
|
|||||||
|
|
||||||
DAEMON = None
|
DAEMON = None
|
||||||
NO_RESIZE = False
|
NO_RESIZE = False
|
||||||
|
WEBSERVER = None
|
||||||
|
|
||||||
maintenanceScheduler = None
|
maintenanceScheduler = None
|
||||||
dailySearchScheduler = None
|
dailySearchScheduler = None
|
||||||
@ -1290,23 +1291,11 @@ def saveAll():
|
|||||||
|
|
||||||
|
|
||||||
def saveAndShutdown(restart=False):
|
def saveAndShutdown(restart=False):
|
||||||
|
global WEBSERVER
|
||||||
|
|
||||||
halt()
|
halt()
|
||||||
saveAll()
|
saveAll()
|
||||||
|
|
||||||
# Shutdown tornado
|
|
||||||
logger.log('Shutting down tornado')
|
|
||||||
|
|
||||||
def shutdown():
|
|
||||||
try:
|
|
||||||
IOLoop.current().stop()
|
|
||||||
except RuntimeError:
|
|
||||||
pass
|
|
||||||
except:
|
|
||||||
logger.log('Failed shutting down the server: %s' % traceback.format_exc(), logger.ERROR)
|
|
||||||
|
|
||||||
IOLoop.current().add_callback(shutdown)
|
|
||||||
|
|
||||||
if CREATEPID:
|
if CREATEPID:
|
||||||
logger.log(u"Removing pidfile " + str(PIDFILE))
|
logger.log(u"Removing pidfile " + str(PIDFILE))
|
||||||
remove_pid_file(PIDFILE)
|
remove_pid_file(PIDFILE)
|
||||||
@ -1337,6 +1326,14 @@ def saveAndShutdown(restart=False):
|
|||||||
|
|
||||||
subprocess.Popen(popen_list, cwd=os.getcwd())
|
subprocess.Popen(popen_list, cwd=os.getcwd())
|
||||||
|
|
||||||
|
logger.log('Shutting down tornado')
|
||||||
|
try:
|
||||||
|
WEBSERVER.stop()
|
||||||
|
except RuntimeError:
|
||||||
|
pass
|
||||||
|
except:
|
||||||
|
logger.log('Failed shutting down the server: %s' % traceback.format_exc(), logger.ERROR)
|
||||||
|
|
||||||
os._exit(0)
|
os._exit(0)
|
||||||
|
|
||||||
|
|
||||||
|
@ -1,7 +1,4 @@
|
|||||||
import os
|
import os
|
||||||
import threading
|
|
||||||
import time
|
|
||||||
import traceback
|
|
||||||
import datetime
|
import datetime
|
||||||
import sickbeard
|
import sickbeard
|
||||||
import webserve
|
import webserve
|
||||||
@ -42,7 +39,7 @@ class webserverInit():
|
|||||||
self.abort = False
|
self.abort = False
|
||||||
|
|
||||||
self.server = None
|
self.server = None
|
||||||
self.thread = None
|
self.ioloop = IOLoop.instance()
|
||||||
|
|
||||||
self.options = options
|
self.options = options
|
||||||
self.options.setdefault('port', 8081)
|
self.options.setdefault('port', 8081)
|
||||||
@ -113,7 +110,8 @@ class webserverInit():
|
|||||||
debug=False,
|
debug=False,
|
||||||
gzip=True,
|
gzip=True,
|
||||||
cookie_secret='61oETzKXQAGaYdkL5gEmGeJJFuYh7EQnp2XdTP1o/Vo=',
|
cookie_secret='61oETzKXQAGaYdkL5gEmGeJJFuYh7EQnp2XdTP1o/Vo=',
|
||||||
login_url='/login'
|
login_url='/login',
|
||||||
|
autoreload=True
|
||||||
)
|
)
|
||||||
|
|
||||||
# Index Handler
|
# Index Handler
|
||||||
@ -147,9 +145,10 @@ class webserverInit():
|
|||||||
logger.log(u"Starting SickRage on " + protocol + "://" + str(self.options['host']) + ":" + str(
|
logger.log(u"Starting SickRage on " + protocol + "://" + str(self.options['host']) + ":" + str(
|
||||||
self.options['port']) + "/")
|
self.options['port']) + "/")
|
||||||
|
|
||||||
self.server.listen(self.options['port'], self.options['host'])
|
|
||||||
|
|
||||||
def start(self):
|
def start(self):
|
||||||
if self.thread == None or not self.thread.isAlive():
|
self.server.listen(self.options['port'], self.options['host'])
|
||||||
self.thread = threading.Thread(target=IOLoop.current().start)
|
self.ioloop.start()
|
||||||
self.thread.start()
|
|
||||||
|
def stop(self):
|
||||||
|
self.server.stop()
|
||||||
|
self.ioloop.stop()
|
Loading…
Reference in New Issue
Block a user