2014-05-29 17:10:49 -04:00
|
|
|
#!/usr/bin/env python2
|
2014-03-10 01:18:05 -04:00
|
|
|
# Author: Nic Wolfe <nic@wolfeden.ca>
|
|
|
|
# URL: http://code.google.com/p/sickbeard/
|
|
|
|
#
|
2014-05-13 07:19:37 -04:00
|
|
|
# This file is part of SickRage.
|
2014-03-10 01:18:05 -04:00
|
|
|
#
|
2014-05-13 07:19:37 -04:00
|
|
|
# SickRage is free software: you can redistribute it and/or modify
|
2014-03-10 01:18:05 -04:00
|
|
|
# it under the terms of the GNU General Public License as published by
|
|
|
|
# the Free Software Foundation, either version 3 of the License, or
|
|
|
|
# (at your option) any later version.
|
|
|
|
#
|
2014-05-13 07:19:37 -04:00
|
|
|
# SickRage is distributed in the hope that it will be useful,
|
2014-03-10 01:18:05 -04:00
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU General Public License
|
2014-05-13 07:19:37 -04:00
|
|
|
# along with SickRage. If not, see <http://www.gnu.org/licenses/>.
|
2014-03-10 01:18:05 -04:00
|
|
|
|
|
|
|
# Check needed software dependencies to nudge users to fix their setup
|
2014-06-18 04:53:11 -04:00
|
|
|
from __future__ import with_statement
|
2014-06-25 23:41:18 -04:00
|
|
|
import functools
|
2014-06-18 04:53:11 -04:00
|
|
|
|
2014-03-10 01:18:05 -04:00
|
|
|
import sys
|
2014-06-19 10:31:44 -04:00
|
|
|
import shutil
|
2014-05-29 03:00:59 -04:00
|
|
|
|
2014-03-10 01:18:05 -04:00
|
|
|
if sys.version_info < (2, 6):
|
|
|
|
print "Sorry, requires Python 2.6 or 2.7."
|
|
|
|
sys.exit(1)
|
|
|
|
|
|
|
|
try:
|
|
|
|
import Cheetah
|
2014-05-29 03:00:59 -04:00
|
|
|
|
2014-03-10 01:18:05 -04:00
|
|
|
if Cheetah.Version[0] != '2':
|
|
|
|
raise ValueError
|
|
|
|
except ValueError:
|
|
|
|
print "Sorry, requires Python module Cheetah 2.1.0 or newer."
|
|
|
|
sys.exit(1)
|
|
|
|
except:
|
|
|
|
print "The Python module Cheetah is required"
|
|
|
|
sys.exit(1)
|
|
|
|
|
|
|
|
import os
|
2014-05-29 03:00:59 -04:00
|
|
|
|
2014-03-10 01:18:05 -04:00
|
|
|
sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), 'lib')))
|
|
|
|
|
|
|
|
# We only need this for compiling an EXE and I will just always do that on 2.6+
|
|
|
|
if sys.hexversion >= 0x020600F0:
|
2014-05-29 03:00:59 -04:00
|
|
|
from multiprocessing import freeze_support # @UnresolvedImport
|
2014-03-10 01:18:05 -04:00
|
|
|
|
|
|
|
import locale
|
2014-04-27 20:25:57 -04:00
|
|
|
import datetime
|
2014-03-10 01:18:05 -04:00
|
|
|
import threading
|
|
|
|
import signal
|
|
|
|
import traceback
|
|
|
|
import getopt
|
2014-06-23 11:18:01 -04:00
|
|
|
import time
|
2014-03-10 01:18:05 -04:00
|
|
|
|
|
|
|
import sickbeard
|
|
|
|
|
2014-06-16 08:19:07 -04:00
|
|
|
import tornado.ioloop
|
|
|
|
import tornado.autoreload
|
|
|
|
|
2014-03-10 01:18:05 -04:00
|
|
|
from sickbeard import db
|
|
|
|
from sickbeard.tv import TVShow
|
|
|
|
from sickbeard import logger
|
2014-06-15 15:11:21 -04:00
|
|
|
from sickbeard import webserveInit
|
2014-06-16 20:48:22 -04:00
|
|
|
from sickbeard import autoreload_shutdown
|
2014-03-10 01:18:05 -04:00
|
|
|
from sickbeard.version import SICKBEARD_VERSION
|
2014-05-13 05:58:27 -04:00
|
|
|
from sickbeard.databases.mainDB import MIN_DB_VERSION
|
2014-03-10 01:18:05 -04:00
|
|
|
from sickbeard.databases.mainDB import MAX_DB_VERSION
|
|
|
|
|
|
|
|
from lib.configobj import ConfigObj
|
|
|
|
|
2014-06-15 09:44:39 -04:00
|
|
|
from tornado.ioloop import IOLoop, PeriodicCallback
|
|
|
|
|
2014-03-10 01:18:05 -04:00
|
|
|
signal.signal(signal.SIGINT, sickbeard.sig_handler)
|
|
|
|
signal.signal(signal.SIGTERM, sickbeard.sig_handler)
|
|
|
|
|
2014-05-29 03:00:59 -04:00
|
|
|
throwaway = datetime.datetime.strptime('20110101', '%Y%m%d')
|
2014-03-10 01:18:05 -04:00
|
|
|
|
|
|
|
def loadShowsFromDB():
|
|
|
|
"""
|
|
|
|
Populates the showList with shows from the database
|
|
|
|
"""
|
|
|
|
|
2014-06-21 18:46:59 -04:00
|
|
|
myDB = db.DBConnection()
|
|
|
|
sqlResults = myDB.select("SELECT * FROM tv_shows")
|
2014-03-10 01:18:05 -04:00
|
|
|
|
2014-06-21 18:46:59 -04:00
|
|
|
for sqlShow in sqlResults:
|
|
|
|
try:
|
|
|
|
curShow = TVShow(int(sqlShow["indexer"]), int(sqlShow["indexer_id"]))
|
|
|
|
sickbeard.showList.append(curShow)
|
|
|
|
except Exception, e:
|
|
|
|
logger.log(
|
|
|
|
u"There was an error creating the show in " + sqlShow["location"] + ": " + str(e).decode('utf-8'),
|
|
|
|
logger.ERROR)
|
|
|
|
logger.log(traceback.format_exc(), logger.DEBUG)
|
2014-03-10 01:18:05 -04:00
|
|
|
|
2014-06-21 18:46:59 -04:00
|
|
|
# TODO: update the existing shows if the showlist has something in it
|
2014-03-10 01:18:05 -04:00
|
|
|
|
|
|
|
def daemonize():
|
|
|
|
try:
|
2014-06-18 14:24:59 -04:00
|
|
|
pid = os.fork()
|
|
|
|
if pid > 0:
|
|
|
|
sys.exit(0)
|
|
|
|
except OSError:
|
|
|
|
print "fork() failed"
|
2014-05-13 07:16:32 -04:00
|
|
|
sys.exit(1)
|
2014-03-10 01:18:05 -04:00
|
|
|
|
2014-06-18 14:24:59 -04:00
|
|
|
os.chdir(sickbeard.PROG_DIR)
|
|
|
|
os.setsid()
|
2014-03-10 01:18:05 -04:00
|
|
|
# Make sure I can read my own files and shut out others
|
2014-06-18 14:24:59 -04:00
|
|
|
prev= os.umask(0)
|
|
|
|
os.umask(prev and int('077',8))
|
2014-03-10 01:18:05 -04:00
|
|
|
|
|
|
|
try:
|
2014-06-18 14:24:59 -04:00
|
|
|
pid = os.fork()
|
|
|
|
if pid > 0:
|
|
|
|
sys.exit(0)
|
|
|
|
except OSError:
|
|
|
|
print "fork() failed"
|
2014-05-13 07:16:32 -04:00
|
|
|
sys.exit(1)
|
2014-03-10 01:18:05 -04:00
|
|
|
|
2014-05-13 07:16:32 -04:00
|
|
|
# Write pid
|
2014-03-10 01:18:05 -04:00
|
|
|
if sickbeard.CREATEPID:
|
|
|
|
pid = str(os.getpid())
|
2014-05-13 07:16:32 -04:00
|
|
|
logger.log(u"Writing PID: " + pid + " to " + str(sickbeard.PIDFILE))
|
|
|
|
try:
|
|
|
|
file(sickbeard.PIDFILE, 'w').write("%s\n" % pid)
|
|
|
|
except IOError, e:
|
|
|
|
logger.log_error_and_exit(
|
|
|
|
u"Unable to write PID file: " + sickbeard.PIDFILE + " Error: " + str(e.strerror) + " [" + str(
|
|
|
|
e.errno) + "]")
|
|
|
|
|
2014-06-18 14:24:59 -04:00
|
|
|
dev_null = file('/dev/null', 'r')
|
|
|
|
os.dup2(dev_null.fileno(), sys.stdin.fileno())
|
2014-03-10 01:18:05 -04:00
|
|
|
|
2014-06-19 10:31:44 -04:00
|
|
|
def restore(srcDir, dstDir):
|
|
|
|
try:
|
|
|
|
for file in os.listdir(srcDir):
|
|
|
|
srcFile = os.path.join(srcDir, file)
|
|
|
|
dstFile = os.path.join(dstDir, file)
|
|
|
|
bakFile = os.path.join(dstDir, file + '.bak')
|
|
|
|
shutil.move(dstFile, bakFile)
|
|
|
|
shutil.move(srcFile, dstFile)
|
|
|
|
|
|
|
|
os.rmdir(srcDir)
|
|
|
|
return True
|
|
|
|
except:
|
|
|
|
return False
|
|
|
|
|
2014-03-10 01:18:05 -04:00
|
|
|
def main():
|
|
|
|
"""
|
|
|
|
TV for me
|
|
|
|
"""
|
|
|
|
|
|
|
|
# do some preliminary stuff
|
|
|
|
sickbeard.MY_FULLNAME = os.path.normpath(os.path.abspath(__file__))
|
|
|
|
sickbeard.MY_NAME = os.path.basename(sickbeard.MY_FULLNAME)
|
|
|
|
sickbeard.PROG_DIR = os.path.dirname(sickbeard.MY_FULLNAME)
|
|
|
|
sickbeard.DATA_DIR = sickbeard.PROG_DIR
|
|
|
|
sickbeard.MY_ARGS = sys.argv[1:]
|
|
|
|
sickbeard.DAEMON = False
|
2014-05-13 07:16:32 -04:00
|
|
|
sickbeard.CREATEPID = False
|
2014-03-10 01:18:05 -04:00
|
|
|
|
|
|
|
sickbeard.SYS_ENCODING = None
|
|
|
|
|
|
|
|
try:
|
|
|
|
locale.setlocale(locale.LC_ALL, "")
|
|
|
|
sickbeard.SYS_ENCODING = locale.getpreferredencoding()
|
|
|
|
except (locale.Error, IOError):
|
|
|
|
pass
|
|
|
|
|
|
|
|
# For OSes that are poorly configured I'll just randomly force UTF-8
|
|
|
|
if not sickbeard.SYS_ENCODING or sickbeard.SYS_ENCODING in ('ANSI_X3.4-1968', 'US-ASCII', 'ASCII'):
|
|
|
|
sickbeard.SYS_ENCODING = 'UTF-8'
|
|
|
|
|
|
|
|
if not hasattr(sys, "setdefaultencoding"):
|
|
|
|
reload(sys)
|
|
|
|
|
|
|
|
try:
|
|
|
|
# pylint: disable=E1101
|
|
|
|
# On non-unicode builds this will raise an AttributeError, if encoding type is not valid it throws a LookupError
|
|
|
|
sys.setdefaultencoding(sickbeard.SYS_ENCODING)
|
|
|
|
except:
|
2014-05-13 07:19:37 -04:00
|
|
|
print 'Sorry, you MUST add the SickRage folder to the PYTHONPATH environment variable'
|
2014-03-10 01:18:05 -04:00
|
|
|
print 'or find another way to force Python to use ' + sickbeard.SYS_ENCODING + ' for string encoding.'
|
|
|
|
sys.exit(1)
|
|
|
|
|
|
|
|
# Need console logging for SickBeard.py and SickBeard-console.exe
|
|
|
|
consoleLogging = (not hasattr(sys, "frozen")) or (sickbeard.MY_NAME.lower().find('-console') > 0)
|
|
|
|
|
|
|
|
# Rename the main thread
|
|
|
|
threading.currentThread().name = "MAIN"
|
|
|
|
|
|
|
|
try:
|
2014-05-29 03:00:59 -04:00
|
|
|
opts, args = getopt.getopt(sys.argv[1:], "qfdp::",
|
|
|
|
['quiet', 'forceupdate', 'daemon', 'port=', 'pidfile=', 'nolaunch', 'config=',
|
|
|
|
'datadir=']) # @UnusedVariable
|
2014-03-10 01:18:05 -04:00
|
|
|
except getopt.GetoptError:
|
|
|
|
print "Available Options: --quiet, --forceupdate, --port, --daemon, --pidfile, --config, --datadir"
|
|
|
|
sys.exit()
|
|
|
|
|
|
|
|
forceUpdate = False
|
|
|
|
forcedPort = None
|
|
|
|
noLaunch = False
|
|
|
|
|
|
|
|
for o, a in opts:
|
|
|
|
# For now we'll just silence the logging
|
|
|
|
if o in ('-q', '--quiet'):
|
|
|
|
consoleLogging = False
|
|
|
|
|
|
|
|
# Should we update (from indexer) all shows in the DB right away?
|
|
|
|
if o in ('-f', '--forceupdate'):
|
|
|
|
forceUpdate = True
|
|
|
|
|
|
|
|
# Suppress launching web browser
|
|
|
|
# Needed for OSes without default browser assigned
|
|
|
|
# Prevent duplicate browser window when restarting in the app
|
|
|
|
if o in ('--nolaunch',):
|
|
|
|
noLaunch = True
|
|
|
|
|
|
|
|
# Override default/configured port
|
|
|
|
if o in ('-p', '--port'):
|
|
|
|
forcedPort = int(a)
|
|
|
|
|
2014-05-13 07:16:32 -04:00
|
|
|
# Run as a double forked daemon
|
2014-03-10 01:18:05 -04:00
|
|
|
if o in ('-d', '--daemon'):
|
2014-05-13 07:16:32 -04:00
|
|
|
sickbeard.DAEMON = True
|
|
|
|
# When running as daemon disable consoleLogging and don't start browser
|
|
|
|
consoleLogging = False
|
|
|
|
noLaunch = True
|
|
|
|
|
2014-03-10 01:18:05 -04:00
|
|
|
if sys.platform == 'win32':
|
2014-05-13 07:16:32 -04:00
|
|
|
sickbeard.DAEMON = False
|
2014-03-10 01:18:05 -04:00
|
|
|
|
|
|
|
# Specify folder to load the config file from
|
|
|
|
if o in ('--config',):
|
|
|
|
sickbeard.CONFIG_FILE = os.path.abspath(a)
|
|
|
|
|
|
|
|
# Specify folder to use as the data dir
|
|
|
|
if o in ('--datadir',):
|
|
|
|
sickbeard.DATA_DIR = os.path.abspath(a)
|
|
|
|
|
2014-06-11 04:34:28 -04:00
|
|
|
# Prevent resizing of the banner/posters even if PIL is installed
|
|
|
|
if o in ('--noresize',):
|
|
|
|
sickbeard.NO_RESIZE = True
|
|
|
|
|
2014-03-10 01:18:05 -04:00
|
|
|
# Write a pidfile if requested
|
|
|
|
if o in ('--pidfile',):
|
2014-05-13 07:16:32 -04:00
|
|
|
sickbeard.CREATEPID = True
|
2014-03-10 01:18:05 -04:00
|
|
|
sickbeard.PIDFILE = str(a)
|
|
|
|
|
|
|
|
# If the pidfile already exists, sickbeard may still be running, so exit
|
|
|
|
if os.path.exists(sickbeard.PIDFILE):
|
2014-05-13 07:16:32 -04:00
|
|
|
sys.exit("PID file: " + sickbeard.PIDFILE + " already exists. Exiting.")
|
|
|
|
|
|
|
|
# The pidfile is only useful in daemon mode, make sure we can write the file properly
|
2014-06-29 01:54:29 -04:00
|
|
|
if sickbeard.CREATEPID and not sickbeard.restarted:
|
2014-05-13 07:16:32 -04:00
|
|
|
if sickbeard.DAEMON:
|
|
|
|
pid_dir = os.path.dirname(sickbeard.PIDFILE)
|
|
|
|
if not os.access(pid_dir, os.F_OK):
|
|
|
|
sys.exit("PID dir: " + pid_dir + " doesn't exist. Exiting.")
|
|
|
|
if not os.access(pid_dir, os.W_OK):
|
|
|
|
sys.exit("PID dir: " + pid_dir + " must be writable (write permissions). Exiting.")
|
|
|
|
|
|
|
|
else:
|
|
|
|
if consoleLogging:
|
|
|
|
sys.stdout.write("Not running in daemon mode. PID file creation disabled.\n")
|
|
|
|
|
|
|
|
sickbeard.CREATEPID = False
|
2014-03-10 01:18:05 -04:00
|
|
|
|
|
|
|
# If they don't specify a config file then put it in the data dir
|
|
|
|
if not sickbeard.CONFIG_FILE:
|
|
|
|
sickbeard.CONFIG_FILE = os.path.join(sickbeard.DATA_DIR, "config.ini")
|
|
|
|
|
|
|
|
# Make sure that we can create the data dir
|
|
|
|
if not os.access(sickbeard.DATA_DIR, os.F_OK):
|
|
|
|
try:
|
|
|
|
os.makedirs(sickbeard.DATA_DIR, 0744)
|
|
|
|
except os.error, e:
|
|
|
|
raise SystemExit("Unable to create datadir '" + sickbeard.DATA_DIR + "'")
|
|
|
|
|
|
|
|
# Make sure we can write to the data dir
|
|
|
|
if not os.access(sickbeard.DATA_DIR, os.W_OK):
|
|
|
|
raise SystemExit("Datadir must be writeable '" + sickbeard.DATA_DIR + "'")
|
|
|
|
|
|
|
|
# Make sure we can write to the config file
|
|
|
|
if not os.access(sickbeard.CONFIG_FILE, os.W_OK):
|
|
|
|
if os.path.isfile(sickbeard.CONFIG_FILE):
|
|
|
|
raise SystemExit("Config file '" + sickbeard.CONFIG_FILE + "' must be writeable.")
|
|
|
|
elif not os.access(os.path.dirname(sickbeard.CONFIG_FILE), os.W_OK):
|
|
|
|
raise SystemExit("Config file root dir '" + os.path.dirname(sickbeard.CONFIG_FILE) + "' must be writeable.")
|
|
|
|
|
2014-06-24 19:40:13 -04:00
|
|
|
# Check if we need to perform a restore first
|
|
|
|
restoreDir = os.path.join(sickbeard.DATA_DIR, 'restore')
|
|
|
|
if os.path.exists(restoreDir):
|
|
|
|
if restore(restoreDir, sickbeard.DATA_DIR):
|
|
|
|
logger.log(u"Restore successful...")
|
|
|
|
else:
|
|
|
|
logger.log(u"Restore FAILED!", logger.ERROR)
|
|
|
|
|
2014-03-10 01:18:05 -04:00
|
|
|
os.chdir(sickbeard.DATA_DIR)
|
|
|
|
|
|
|
|
if consoleLogging:
|
2014-05-13 07:19:37 -04:00
|
|
|
print "Starting up SickRage " + SICKBEARD_VERSION + " from " + sickbeard.CONFIG_FILE
|
2014-03-10 01:18:05 -04:00
|
|
|
|
|
|
|
# Load the config and publish it to the sickbeard package
|
|
|
|
if not os.path.isfile(sickbeard.CONFIG_FILE):
|
|
|
|
logger.log(u"Unable to find '" + sickbeard.CONFIG_FILE + "' , all settings will be default!", logger.ERROR)
|
|
|
|
|
|
|
|
sickbeard.CFG = ConfigObj(sickbeard.CONFIG_FILE)
|
|
|
|
|
2014-06-25 20:12:52 -04:00
|
|
|
CUR_DB_VERSION = db.DBConnection().checkDBVersion()
|
2014-06-07 17:32:38 -04:00
|
|
|
|
2014-03-10 01:18:05 -04:00
|
|
|
if CUR_DB_VERSION > 0:
|
|
|
|
if CUR_DB_VERSION < MIN_DB_VERSION:
|
2014-05-29 03:00:59 -04:00
|
|
|
raise SystemExit("Your database version (" + str(
|
2014-06-07 17:32:38 -04:00
|
|
|
CUR_DB_VERSION) + ") is too old to migrate from with this version of SickRage (" + str(
|
2014-05-29 03:00:59 -04:00
|
|
|
MIN_DB_VERSION) + ").\n" + \
|
2014-03-10 01:18:05 -04:00
|
|
|
"Upgrade using a previous version of SB first, or start with no database file to begin fresh.")
|
|
|
|
if CUR_DB_VERSION > MAX_DB_VERSION:
|
2014-05-29 03:00:59 -04:00
|
|
|
raise SystemExit("Your database version (" + str(
|
2014-06-07 17:32:38 -04:00
|
|
|
CUR_DB_VERSION) + ") has been incremented past what this version of SickRage supports (" + str(
|
2014-05-29 03:00:59 -04:00
|
|
|
MAX_DB_VERSION) + ").\n" + \
|
2014-05-13 05:58:27 -04:00
|
|
|
"If you have used other forks of SB, your database may be unusable due to their modifications.")
|
|
|
|
|
2014-06-25 20:12:52 -04:00
|
|
|
# Initialize the config and our threads
|
|
|
|
sickbeard.initialize(consoleLogging=consoleLogging)
|
|
|
|
|
|
|
|
sickbeard.showList = []
|
|
|
|
|
2014-06-27 10:47:29 -04:00
|
|
|
if sickbeard.DAEMON:
|
2014-06-18 19:17:53 -04:00
|
|
|
daemonize()
|
|
|
|
|
|
|
|
# Use this PID for everything
|
|
|
|
sickbeard.PID = os.getpid()
|
|
|
|
|
2014-06-25 20:12:52 -04:00
|
|
|
# Build from the DB to start with
|
|
|
|
logger.log(u"Loading initial show list")
|
|
|
|
loadShowsFromDB()
|
2014-03-10 01:18:05 -04:00
|
|
|
|
|
|
|
if forcedPort:
|
|
|
|
logger.log(u"Forcing web server to port " + str(forcedPort))
|
|
|
|
startPort = forcedPort
|
|
|
|
else:
|
|
|
|
startPort = sickbeard.WEB_PORT
|
|
|
|
|
|
|
|
if sickbeard.WEB_LOG:
|
|
|
|
log_dir = sickbeard.LOG_DIR
|
|
|
|
else:
|
|
|
|
log_dir = None
|
|
|
|
|
|
|
|
# sickbeard.WEB_HOST is available as a configuration value in various
|
|
|
|
# places but is not configurable. It is supported here for historic reasons.
|
|
|
|
if sickbeard.WEB_HOST and sickbeard.WEB_HOST != '0.0.0.0':
|
|
|
|
webhost = sickbeard.WEB_HOST
|
|
|
|
else:
|
|
|
|
if sickbeard.WEB_IPV6:
|
|
|
|
webhost = '::'
|
|
|
|
else:
|
|
|
|
webhost = '0.0.0.0'
|
|
|
|
|
2014-06-11 04:34:28 -04:00
|
|
|
options = {
|
|
|
|
'port': int(startPort),
|
|
|
|
'host': webhost,
|
|
|
|
'data_root': os.path.join(sickbeard.PROG_DIR, 'gui', sickbeard.GUI_NAME),
|
|
|
|
'web_root': sickbeard.WEB_ROOT,
|
|
|
|
'log_dir': log_dir,
|
|
|
|
'username': sickbeard.WEB_USERNAME,
|
|
|
|
'password': sickbeard.WEB_PASSWORD,
|
|
|
|
'enable_https': sickbeard.ENABLE_HTTPS,
|
|
|
|
'handle_reverse_proxy': sickbeard.HANDLE_REVERSE_PROXY,
|
|
|
|
'https_cert': sickbeard.HTTPS_CERT,
|
|
|
|
'https_key': sickbeard.HTTPS_KEY,
|
2014-06-18 19:17:53 -04:00
|
|
|
}
|
2014-06-11 04:34:28 -04:00
|
|
|
|
2014-06-15 15:11:21 -04:00
|
|
|
# init tornado
|
2014-06-25 23:41:18 -04:00
|
|
|
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()
|
2014-03-10 01:18:05 -04:00
|
|
|
|
2014-06-15 15:11:21 -04:00
|
|
|
def startup():
|
2014-06-15 09:44:39 -04:00
|
|
|
# Fire up all our threads
|
|
|
|
sickbeard.start()
|
|
|
|
|
2014-06-15 08:43:53 -04:00
|
|
|
# Launch browser if we're supposed to
|
2014-06-23 23:25:20 -04:00
|
|
|
if sickbeard.LAUNCH_BROWSER and not noLaunch and not sickbeard.DAEMON and not sickbeard.restarted:
|
2014-06-15 08:43:53 -04:00
|
|
|
sickbeard.launchBrowser(startPort)
|
2014-03-10 01:18:05 -04:00
|
|
|
|
2014-06-15 08:43:53 -04:00
|
|
|
# Start an update if we're supposed to
|
|
|
|
if forceUpdate or sickbeard.UPDATE_SHOWS_ON_START:
|
|
|
|
sickbeard.showUpdateScheduler.action.run(force=True) # @UndefinedVariable
|
2014-03-10 01:18:05 -04:00
|
|
|
|
2014-06-25 23:41:18 -04:00
|
|
|
# If we restarted then unset the restarted flag
|
2014-06-23 23:25:20 -04:00
|
|
|
if sickbeard.restarted:
|
|
|
|
sickbeard.restarted = False
|
|
|
|
|
2014-06-18 19:17:53 -04:00
|
|
|
# create ioloop
|
|
|
|
io_loop = IOLoop.current()
|
|
|
|
|
2014-06-16 06:44:33 -04:00
|
|
|
io_loop.add_timeout(datetime.timedelta(seconds=5), startup)
|
|
|
|
|
2014-06-18 19:17:53 -04:00
|
|
|
io_loop.start()
|
|
|
|
sickbeard.saveAndShutdown()
|
2014-06-18 16:12:19 -04:00
|
|
|
|
2014-03-10 01:18:05 -04:00
|
|
|
if __name__ == "__main__":
|
|
|
|
if sys.hexversion >= 0x020600F0:
|
|
|
|
freeze_support()
|
2014-06-23 11:18:01 -04:00
|
|
|
|
|
|
|
while(True):
|
|
|
|
main()
|
|
|
|
|
|
|
|
# check if restart was requested
|
|
|
|
if not sickbeard.restarted:
|
|
|
|
if sickbeard.CREATEPID:
|
|
|
|
logger.log(u"Removing pidfile " + str(sickbeard.PIDFILE))
|
|
|
|
sickbeard.remove_pid_file(sickbeard.PIDFILE)
|
|
|
|
break
|
|
|
|
|
|
|
|
# restart
|
|
|
|
logger.log("Restarting SickRage, please stand by...")
|