Better shutdown of process

This commit is contained in:
Ruud committed 2012-03-10 17:07:19 +01:00
1 parent bfbd3b26a9
commit 088dc5386c
3 files changed
+32 -2

No files matched your search

+2 -1
View File
@@ -85,7 +85,8 @@ class Loader(object):
# remove old pidfile first # remove old pidfile first
try: try:
if self.runAsDaemon(): if self.runAsDaemon():
self.daemon.stop() try: self.daemon.stop()
except: pass
self.daemon.delpid() self.daemon.delpid()
except: except:
self.log.critical(traceback.format_exc()) self.log.critical(traceback.format_exc())
+7
View File
@@ -56,6 +56,9 @@ class Core(Plugin):
}) })
def crappyShutdown(self): def crappyShutdown(self):
if self.shutdown_started:
return
try: try:
self.urlopen('%s/app.shutdown' % self.createApiUrl(), show_error = False) self.urlopen('%s/app.shutdown' % self.createApiUrl(), show_error = False)
return True return True
@@ -64,6 +67,9 @@ class Core(Plugin):
return False return False
def crappyRestart(self): def crappyRestart(self):
if self.shutdown_started:
return
try: try:
self.urlopen('%s/app.restart' % self.createApiUrl(), show_error = False) self.urlopen('%s/app.restart' % self.createApiUrl(), show_error = False)
return True return True
@@ -82,6 +88,7 @@ class Core(Plugin):
def initShutdown(self, restart = False): def initShutdown(self, restart = False):
if self.shutdown_started: if self.shutdown_started:
log.info('Already shutting down') log.info('Already shutting down')
return
log.info('Shutting down' if not restart else 'Restarting') log.info('Shutting down' if not restart else 'Restarting')
+23 -1
View File
@@ -186,4 +186,26 @@ def runCouchPotato(options, base_path, args, data_dir = None, log_dir = None, En
if fire_load: fireEventAsync('app.load') if fire_load: fireEventAsync('app.load')
# Go go go! # 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