Better shutdown of process
This commit is contained in:
+2
-1
@@ -85,7 +85,8 @@ class Loader(object):
|
||||
# remove old pidfile first
|
||||
try:
|
||||
if self.runAsDaemon():
|
||||
self.daemon.stop()
|
||||
try: self.daemon.stop()
|
||||
except: pass
|
||||
self.daemon.delpid()
|
||||
except:
|
||||
self.log.critical(traceback.format_exc())
|
||||
|
||||
@@ -56,6 +56,9 @@ class Core(Plugin):
|
||||
})
|
||||
|
||||
def crappyShutdown(self):
|
||||
if self.shutdown_started:
|
||||
return
|
||||
|
||||
try:
|
||||
self.urlopen('%s/app.shutdown' % self.createApiUrl(), show_error = False)
|
||||
return True
|
||||
@@ -64,6 +67,9 @@ class Core(Plugin):
|
||||
return False
|
||||
|
||||
def crappyRestart(self):
|
||||
if self.shutdown_started:
|
||||
return
|
||||
|
||||
try:
|
||||
self.urlopen('%s/app.restart' % self.createApiUrl(), show_error = False)
|
||||
return True
|
||||
@@ -82,6 +88,7 @@ class Core(Plugin):
|
||||
def initShutdown(self, restart = False):
|
||||
if self.shutdown_started:
|
||||
log.info('Already shutting down')
|
||||
return
|
||||
|
||||
log.info('Shutting down' if not restart else 'Restarting')
|
||||
|
||||
|
||||
+23
-1
@@ -186,4 +186,26 @@ def runCouchPotato(options, base_path, args, data_dir = None, log_dir = None, En
|
||||
if fire_load: fireEventAsync('app.load')
|
||||
|
||||
# Go go go!
|
||||
app.run(**config)
|
||||
try_restart = True
|
||||
restart_tries = 5
|
||||
while try_restart:
|
||||
try:
|
||||
app.run(**config)
|
||||
except Exception, e:
|
||||
try:
|
||||
nr, msg = e
|
||||
if nr == 48:
|
||||
log.info('Already in use, try %s more time after few seconds' % restart_tries)
|
||||
time.sleep(1)
|
||||
restart_tries -= 1
|
||||
|
||||
if restart_tries > 0:
|
||||
continue
|
||||
else:
|
||||
return
|
||||
except:
|
||||
pass
|
||||
|
||||
raise
|
||||
|
||||
try_restart = False
|
||||
|
||||
Reference in New Issue
Block a user