Rework restart methods

This commit is contained in:
Ruud
2014-06-23 01:09:32 +02:00
parent 1c5f19a68a
commit 94064ac7da
7 changed files with 31 additions and 19 deletions
+3 -3
View File
@@ -72,10 +72,11 @@ class Loader(object):
signal.signal(signal.SIGTERM, lambda signum, stack_frame: sys.exit(1))
from couchpotato.core.event import addEvent
addEvent('app.after_shutdown', self.afterShutdown)
addEvent('app.do_shutdown', self.setRestart)
def afterShutdown(self, restart):
def setRestart(self, restart):
self.do_restart = restart
return True
def onExit(self, signal, frame):
from couchpotato.core.event import fireEvent
@@ -103,7 +104,6 @@ class Loader(object):
# Release log files and shutdown logger
logging.shutdown()
time.sleep(3)
args = [sys.executable] + [os.path.join(base_path, os.path.basename(__file__))] + sys.argv[1:]
subprocess.Popen(args)
+5 -3
View File
@@ -118,7 +118,7 @@ class Core(Plugin):
self.shutdown_started = True
fireEvent('app.do_shutdown')
fireEvent('app.do_shutdown', restart = restart)
log.debug('Every plugin got shutdown event')
loop = True
@@ -143,9 +143,11 @@ class Core(Plugin):
log.debug('Safe to shutdown/restart')
loop = IOLoop.current()
try:
if not IOLoop.current()._closing:
IOLoop.current().stop()
if not loop._closing:
loop.stop()
except RuntimeError:
pass
except:
+2 -2
View File
@@ -33,9 +33,9 @@ class Scheduler(Plugin):
except:
pass
def doShutdown(self):
def doShutdown(self, *args, **kwargs):
self.stop()
return super(Scheduler, self).doShutdown()
return super(Scheduler, self).doShutdown(*args, **kwargs)
def stop(self):
if self.started:
+2 -2
View File
@@ -142,11 +142,11 @@ class Updater(Plugin):
'success': success
}
def doShutdown(self):
def doShutdown(self, *args, **kwargs):
if not Env.get('dev'):
removePyc(Env.get('app_dir'), show_logs = False)
return super(Updater, self).doShutdown()
return super(Updater, self).doShutdown(*args, **kwargs)
class BaseUpdater(Plugin):
+1 -1
View File
@@ -263,7 +263,7 @@ class Plugin(object):
def afterCall(self, handler):
self.isRunning('%s.%s' % (self.getName(), handler.__name__), False)
def doShutdown(self):
def doShutdown(self, *args, **kwargs):
self.shuttingDown(True)
return True
+7 -4
View File
@@ -286,13 +286,14 @@ def runCouchPotato(options, base_path, args, data_dir = None, log_dir = None, En
except: pass
fireEventAsync('app.load')
ssl_options = None
if config['ssl_cert'] and config['ssl_key']:
server = HTTPServer(application, no_keep_alive = True, ssl_options = {
ssl_options = {
'certfile': config['ssl_cert'],
'keyfile': config['ssl_key'],
})
else:
server = HTTPServer(application, no_keep_alive = True)
}
server = HTTPServer(application, no_keep_alive = True)
try_restart = True
restart_tries = 5
@@ -301,6 +302,8 @@ def runCouchPotato(options, base_path, args, data_dir = None, log_dir = None, En
try:
server.listen(config['port'], config['host'])
loop.start()
server.close_all_connections()
server.stop()
except Exception as e:
log.error('Failed starting: %s', traceback.format_exc())
try:
+11 -4
View File
@@ -272,11 +272,18 @@
(function(){
Api.request('app.available', {
'onFailure': function(){
self.checkAvailable.delay(1000, self, [delay, onAvailable]);
self.fireEvent('unload');
var onFailure = function(){
self.checkAvailable.delay(1000, self, [delay, onAvailable]);
self.fireEvent('unload');
}
var request = Api.request('app.available', {
'timeout': 2000,
'onTimeout': function(){
request.cancel();
onFailure();
},
'onFailure': onFailure,
'onSuccess': function(){
if(onAvailable)
onAvailable();