Browse Source

Better shutdown of process

pull/84/head
Ruud 13 years ago
parent
commit
088dc5386c
  1. 3
      CouchPotato.py
  2. 7
      couchpotato/core/_base/_core/main.py
  3. 24
      couchpotato/runner.py

3
CouchPotato.py

@ -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())

7
couchpotato/core/_base/_core/main.py

@ -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')

24
couchpotato/runner.py

@ -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

Loading…
Cancel
Save