Shutdown event
This commit is contained in:
@@ -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')
|
||||
|
||||
Reference in New Issue
Block a user