Proper loading of plugins on debug

Restarting functions
This commit is contained in:
Ruud
2011-08-29 18:07:19 +02:00
parent f9c70d46fe
commit 9ff4d0bc91
7 changed files with 140 additions and 32 deletions
+2 -1
View File
@@ -1,7 +1,8 @@
from .main import Core
from uuid import uuid4
def start():
pass
return Core()
config = [{
'name': 'core',
+54
View File
@@ -0,0 +1,54 @@
from couchpotato.api import addApiView
from couchpotato.core.event import fireEvent
from couchpotato.core.logger import CPLog
from couchpotato.core.plugins.base import Plugin
from couchpotato.environment import Env
from flask import request
import os
log = CPLog(__name__)
class Core(Plugin):
def __init__(self):
addApiView('app.shutdown', self.shutdown)
addApiView('app.restart', self.restart)
self.removeRestartFile()
def shutdown(self):
self.initShutdown()
return 'shutdown'
def restart(self):
self.initShutdown(restart = True)
return 'restarting'
def initShutdown(self, restart = False):
fireEvent('app.shutdown')
if restart:
self.writeRestartFile()
func = request.environ.get('werkzeug.server.shutdown')
if func is None:
raise RuntimeError('Not running with the Werkzeug Server')
func()
def removeRestartFile(self):
try:
os.remove(self.restartFilePath())
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')
+1
View File
@@ -20,6 +20,7 @@ class Scheduler(Plugin):
addEvent('schedule.restart', self.start)
addEvent('app.load', self.start)
addEvent('app.shutdown', self.stop)
self.sched = Sched(misfire_grace_time = 60)