1
0
mirror of https://github.com/moparisthebest/SickRage synced 2024-11-18 07:15:13 -05:00

Merge remote-tracking branch 'origin/dev'

This commit is contained in:
echel0n 2014-06-18 13:14:04 -07:00
commit 8fdfbaa960
3 changed files with 27 additions and 49 deletions

View File

@ -91,41 +91,33 @@ def loadShowsFromDB():
sickbeard.showList.append(curShow) sickbeard.showList.append(curShow)
except Exception, e: except Exception, e:
logger.log( logger.log(
u"There was an error creating the show in " + sqlShow["location"] + ": " + str(e).decode('utf-8'), u"There was an error creating the show in " + sqlShow["location"] + ": " + str(e).decode('utf-8'),
logger.ERROR) logger.ERROR)
logger.log(traceback.format_exc(), logger.DEBUG) logger.log(traceback.format_exc(), logger.DEBUG)
# TODO: update the existing shows if the showlist has something in it # TODO: update the existing shows if the showlist has something in it
def daemonize(): def daemonize():
"""
Fork off as a daemon
"""
# pylint: disable=E1101
# Make a non-session-leader child process
try: try:
pid = os.fork() # @UndefinedVariable - only available in UNIX pid = os.fork()
if pid != 0: if pid > 0:
os._exit(0) sys.exit(0)
except OSError, e: except OSError:
sys.stderr.write("fork #1 failed: %d (%s)\n" % (e.errno, e.strerror)) print "fork() failed"
sys.exit(1) sys.exit(1)
os.setsid() # unix os.chdir(sickbeard.PROG_DIR)
os.setsid()
# Make sure I can read my own files and shut out others # Make sure I can read my own files and shut out others
prev = os.umask(0) prev= os.umask(0)
os.umask(prev and int('077', 8)) os.umask(prev and int('077',8))
# Make the child a session-leader by detaching from the terminal
try: try:
pid = os.fork() # @UndefinedVariable - only available in UNIX pid = os.fork()
if pid != 0: if pid > 0:
os._exit(0) sys.exit(0)
except OSError, e: except OSError:
sys.stderr.write("fork #2 failed: %d (%s)\n" % (e.errno, e.strerror)) print "fork() failed"
sys.exit(1) sys.exit(1)
# Write pid # Write pid
@ -139,25 +131,14 @@ def daemonize():
u"Unable to write PID file: " + sickbeard.PIDFILE + " Error: " + str(e.strerror) + " [" + str( u"Unable to write PID file: " + sickbeard.PIDFILE + " Error: " + str(e.strerror) + " [" + str(
e.errno) + "]") e.errno) + "]")
# Redirect all output dev_null = file('/dev/null', 'r')
sys.stdout.flush() os.dup2(dev_null.fileno(), sys.stdin.fileno())
sys.stderr.flush()
devnull = getattr(os, 'devnull', '/dev/null')
stdin = file(devnull, 'r')
stdout = file(devnull, 'a+')
stderr = file(devnull, 'a+')
os.dup2(stdin.fileno(), sys.stdin.fileno())
os.dup2(stdout.fileno(), sys.stdout.fileno())
os.dup2(stderr.fileno(), sys.stderr.fileno())
def main(): def main():
""" """
TV for me TV for me
""" """
io_loop = IOLoop.current()
# do some preliminary stuff # do some preliminary stuff
sickbeard.MY_FULLNAME = os.path.normpath(os.path.abspath(__file__)) sickbeard.MY_FULLNAME = os.path.normpath(os.path.abspath(__file__))
sickbeard.MY_NAME = os.path.basename(sickbeard.MY_FULLNAME) sickbeard.MY_NAME = os.path.basename(sickbeard.MY_FULLNAME)
@ -327,12 +308,6 @@ def main():
sickbeard.showList = [] sickbeard.showList = []
if sickbeard.DAEMON:
daemonize()
# Use this PID for everything
sickbeard.PID = os.getpid()
if forcedPort: if forcedPort:
logger.log(u"Forcing web server to port " + str(forcedPort)) logger.log(u"Forcing web server to port " + str(forcedPort))
startPort = forcedPort startPort = forcedPort
@ -387,6 +362,9 @@ 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
# get ioloop
io_loop = IOLoop.current()
# init startup tasks # init startup tasks
io_loop.add_timeout(datetime.timedelta(seconds=5), startup) io_loop.add_timeout(datetime.timedelta(seconds=5), startup)
@ -395,6 +373,12 @@ def main():
if sickbeard.AUTO_UPDATE: if sickbeard.AUTO_UPDATE:
tornado.autoreload.start(io_loop) tornado.autoreload.start(io_loop)
if sickbeard.DAEMON:
daemonize()
# Use this PID for everything
sickbeard.PID = os.getpid()
# start IOLoop. # start IOLoop.
io_loop.start() io_loop.start()
sickbeard.saveAndShutdown() sickbeard.saveAndShutdown()

View File

@ -83,14 +83,7 @@ from Cheetah.Template import Template
from tornado import gen from tornado import gen
from tornado.web import RequestHandler, HTTPError, asynchronous from tornado.web import RequestHandler, HTTPError, asynchronous
# def _handle_reverse_proxy():
# if sickbeard.HANDLE_REVERSE_PROXY:
# cherrypy.lib.cptools.proxy()
# cherrypy.tools.handle_reverse_proxy = cherrypy.Tool('before_handler', _handle_reverse_proxy)
req_headers = None req_headers = None
def authenticated(handler_class): def authenticated(handler_class):
def wrap_execute(handler_execute): def wrap_execute(handler_execute):
def basicauth(handler, transforms, *args, **kwargs): def basicauth(handler, transforms, *args, **kwargs):

View File

@ -67,6 +67,7 @@ def initWebServer(options={}):
app = Application([], app = Application([],
debug=sickbeard.DEBUG, debug=sickbeard.DEBUG,
gzip=True, gzip=True,
xheaders=sickbeard.HANDLE_REVERSE_PROXY,
cookie_secret='61oETzKXQAGaYdkL5gEmGeJJFuYh7EQnp2XdTP1o/Vo=' cookie_secret='61oETzKXQAGaYdkL5gEmGeJJFuYh7EQnp2XdTP1o/Vo='
) )