Updates/Restarts now use the same process instead of spawning a new one so the PID remains the same.

Fixed issue for restarts/updates on windows.
This commit is contained in:
echel0n 2014-06-23 08:18:01 -07:00
parent 3c370fc5c9
commit 386355e130
5 changed files with 30 additions and 47 deletions

View file

@ -53,6 +53,7 @@ import threading
import signal
import traceback
import getopt
import time
import sickbeard
@ -380,6 +381,9 @@ def main():
loadShowsFromDB()
def startup():
if sickbeard.restarted:
sickbeard.restarted = False
# Fire up all our threads
sickbeard.start()
@ -408,4 +412,16 @@ def main():
if __name__ == "__main__":
if sys.hexversion >= 0x020600F0:
freeze_support()
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...")

View file

@ -13,7 +13,7 @@ else
var base_url = window.location.protocol+'//'+window.location.host+sbRoot;
var is_alive_url = sbRoot+'/home/is_alive';
var timeout_id;
var current_pid = '';
var restarted = '';
var num_restart_waits = 0;
function is_alive() {
@ -28,9 +28,9 @@ function is_alive() {
setTimeout('is_alive()', 1000);
} else {
// if this is before we've even shut down then just try again later
if (current_pid == '' || data.msg == current_pid) {
current_pid = data.msg;
setTimeout(is_alive, 1000);
if (restarted == '' || data.restarted == restarted) {
restarted = data.restarted;
setTimeout('is_alive()', 1000);
// if we're ready to go then redirect to new url
} else {

View file

@ -477,7 +477,7 @@ def initialize(consoleLogging=True):
USE_FAILED_DOWNLOADS, DELETE_FAILED, ANON_REDIRECT, LOCALHOST_IP, REMOTE_IP, TMDB_API_KEY, DEBUG, PROXY_SETTING, \
AUTOPOSTPROCESSER_FREQUENCY, DEFAULT_AUTOPOSTPROCESSER_FREQUENCY, MIN_AUTOPOSTPROCESSER_FREQUENCY, \
ANIME_DEFAULT, NAMING_ANIME, ANIMESUPPORT, USE_ANIDB, ANIDB_USERNAME, ANIDB_PASSWORD, ANIDB_USE_MYLIST, \
ANIME_SPLIT_HOME, maintenanceScheduler, SCENE_DEFAULT
ANIME_SPLIT_HOME, maintenanceScheduler, SCENE_DEFAULT, RES
if __INITIALIZED__:
return False
@ -1309,44 +1309,9 @@ def cleanup_tornado_sockets(io_loop):
pass
def saveAndShutdown():
halt()
saveAll()
cleanup_tornado_sockets(IOLoop.current())
if CREATEPID:
logger.log(u"Removing pidfile " + str(PIDFILE))
remove_pid_file(PIDFILE)
if restarted:
install_type = versionCheckScheduler.action.install_type
popen_list = []
if install_type in ('git', 'source'):
popen_list = [sys.executable, MY_FULLNAME]
elif install_type == 'win':
if hasattr(sys, 'frozen'):
# c:\dir\to\updater.exe 12345 c:\dir\to\sickbeard.exe
popen_list = [os.path.join(PROG_DIR, 'updater.exe'), str(PID), sys.executable]
else:
logger.log(u"Unknown SB launch method, please file a bug report about this", logger.ERROR)
popen_list = [sys.executable, os.path.join(PROG_DIR, 'updater.py'), str(PID), sys.executable,
MY_FULLNAME]
if popen_list:
popen_list += MY_ARGS
if '--nolaunch' not in popen_list:
popen_list += ['--nolaunch']
logger.log(u"Restarting SickRage with " + str(popen_list))
logger.close()
subprocess.Popen(popen_list, cwd=os.getcwd())
os._exit(0)
def invoke_command(to_call, *args, **kwargs):
def delegate():
@ -1375,6 +1340,7 @@ def restart(soft=True):
initialize()
else:
restarted=True
time.sleep(5)
webserveInit.shutdown()

View file

@ -3004,9 +3004,9 @@ class Home(MainHandler):
self.set_header('Access-Control-Allow-Headers', 'x-requested-with')
if sickbeard.started:
return callback + '(' + json.dumps({"msg": str(sickbeard.PID)}) + ');'
return callback + '(' + json.dumps({"msg": str(sickbeard.PID), "restarted": str(sickbeard.restarted)}) + ');'
else:
return callback + '(' + json.dumps({"msg": "nope"}) + ');'
return callback + '(' + json.dumps({"msg": "nope", "restarted": str(sickbeard.restarted)}) + ');'
def index(self, *args, **kwargs):
@ -3322,8 +3322,8 @@ class Home(MainHandler):
t = PageTemplate(file="restart.tmpl")
t.submenu = HomeMenu()
# do a soft restart
threading.Timer(2, sickbeard.invoke_restart, [False]).start()
# restart
threading.Timer(5, sickbeard.invoke_restart, [False]).start()
return _munge(t)

View file

@ -1,5 +1,6 @@
import os
import traceback
import time
import sickbeard
import webserve
import webapi
@ -114,10 +115,10 @@ def initWebServer(options={}):
def shutdown():
global server
logger.log('Shutting down tornado')
logger.log('Shutting down tornado io loop')
try:
IOLoop.current().stop()
except RuntimeError:
pass
except:
logger.log('Failed shutting down the server: %s' % traceback.format_exc(), logger.ERROR)
logger.log('Failed shutting down tornado io loop: %s' % traceback.format_exc(), logger.ERROR)