Shutdown/restart signals now handled by the main thread

This commit is contained in:
Remy
2011-08-12 17:19:53 -07:00
parent 337a952a2b
commit d330accbfc
3 changed files with 24 additions and 10 deletions

View File

@@ -1,5 +1,6 @@
#!/usr/bin/env python
import os, sys
import time
from lib.configobj import ConfigObj
@@ -99,6 +100,20 @@ def main():
# Start the background threads
headphones.start()
while True:
if not headphones.SIGNAL:
time.sleep(1)
else:
logger.info('Received signal: ' + headphones.SIGNAL)
if headphones.SIGNAL == 'shutdown':
headphones.shutdown()
elif headphones.SIGNAL == 'restart':
headphones.shutdown(restart=True)
else:
headphones.shutdown(restart=True, update=True)
headphones.SIGNAL = None
return
if __name__ == "__main__":

View File

@@ -18,7 +18,7 @@ FULL_PATH = None
PROG_DIR = None
ARGS = None
INVOKED_COMMAND = None
SIGNAL = None
QUIET = False
DAEMON = False
@@ -496,20 +496,23 @@ def dbcheck():
def shutdown(restart=False, update=False):
cherrypy.engine.exit()
SCHED.shutdown(wait=False)
config_write()
if not restart and not update:
logger.info('Headphones is shutting down...')
if update:
logger.info('Headphones is updating...')
try:
versioncheck.update()
except Exception, e:
logger.warn('Headphones failed to update: %s. Restarting.' % e)
if restart:
logger.info('Headphones is restarting...')
popen_list = [sys.executable, FULL_PATH]
popen_list += ARGS
if '--nolaunch' not in popen_list:

View File

@@ -397,8 +397,7 @@ class WebInterface(object):
configUpdate.exposed = True
def shutdown(self):
logger.info(u"Headphones is shutting down...")
threading.Timer(2, headphones.shutdown).start()
headphones.SIGNAL = 'shutdown'
message = 'Shutting Down...'
return serve_template(templatename="shutdown.html", title="Shutting Down", message=message, timer=15)
return page
@@ -406,19 +405,16 @@ class WebInterface(object):
shutdown.exposed = True
def restart(self):
logger.info(u"Headphones is restarting...")
threading.Timer(2, headphones.shutdown, [True]).start()
headphones.SIGNAL = 'restart'
message = 'Restarting...'
return serve_template(templatename="shutdown.html", title="Restarting", message=message, timer=30)
restart.exposed = True
def update(self):
logger.info('Headphones is updating...')
threading.Timer(2, headphones.shutdown, [True, True]).start()
headphones.SIGNAL = 'update'
message = 'Updating...'
return serve_template(templatename="shutdown.html", title="Updating", message=message, timer=120)
return page
update.exposed = True
def extras(self):