Shutdown event

This commit is contained in:
Ruud
2011-08-29 23:58:35 +02:00
parent a77dc35613
commit 4fd3f91a77
6 changed files with 85 additions and 48 deletions
+16 -9
View File
@@ -5,6 +5,7 @@ from couchpotato.core.plugins.base import Plugin
from couchpotato.environment import Env
from flask import request
import os
import time
log = CPLog(__name__)
@@ -29,12 +30,25 @@ class Core(Plugin):
fireEvent('app.shutdown')
while 1:
still_running = fireEvent('plugin.running')
brk = True
for running in still_running:
if running > 0:
brk = False
if brk: break
time.sleep(1)
if restart:
self.writeRestartFile()
self.createFile(self.restartFilePath(), 'This is the most suckiest way to register if CP is restarted. Ever...')
func = request.environ.get('werkzeug.server.shutdown')
if func is None:
raise RuntimeError('Not running with the Werkzeug Server')
log.error('Failed shutting down the server')
func()
def removeRestartFile(self):
@@ -43,12 +57,5 @@ class Core(Plugin):
except:
pass
def writeRestartFile(self):
try:
with open(self.restartFilePath(), 'w') as f:
f.write('This is the most suckiest way to register if CP is restarted. Ever...')
except Exception, e:
log.error('Could not write shutdown file: %s' % e)
def restartFilePath(self):
return os.path.join(Env.get('data_dir'), 'restart')