summaryrefslogtreecommitdiff
path: root/ick_controller.py
diff options
context:
space:
mode:
authorLars Wirzenius <liw@liw.fi>2017-10-13 14:35:08 +0300
committerLars Wirzenius <liw@liw.fi>2017-10-13 14:35:08 +0300
commit1079cc8ff295ca11e65c2a864e41789ddc6ed205 (patch)
tree6931a3bee6dbfd30984a77893f6d8fd263317401 /ick_controller.py
parenta20ad580ef9d62dee87ca1b8ff6aa6992bfee23c (diff)
downloadick2-1079cc8ff295ca11e65c2a864e41789ddc6ed205.tar.gz
Add: wrap main program of controller in a try/except to log errors
Diffstat (limited to 'ick_controller.py')
-rw-r--r--ick_controller.py62
1 files changed, 39 insertions, 23 deletions
diff --git a/ick_controller.py b/ick_controller.py
index 855b6ea..59ac86a 100644
--- a/ick_controller.py
+++ b/ick_controller.py
@@ -18,6 +18,7 @@
import logging
import logging.handlers
import os
+import sys
import apifw
@@ -55,37 +56,52 @@ def load_config(filename, defconf):
return actual_config
-logger = logging.getLogger()
-logger.setLevel(logging.DEBUG)
-handler = logging.FileHandler('/tmp/ick.log')
-logger.addHandler(handler)
-logging.info('Starting ick controller main program')
+def main():
+ logger = logging.getLogger()
+ logger.setLevel(logging.DEBUG)
+ handler = logging.FileHandler('/tmp/ick.log')
+ logger.addHandler(handler)
+ logging.info('Starting ick controller main program')
-config_filename = os.environ.get('ICK_CONTROLLER_CONFIG')
-logging.info('config filename %r', config_filename)
-if not config_filename:
- logging.error('no ICK_CONTROLLER_CONFIG in environment')
- raise Exception('No ICK_CONTROLLER_CONFIG defined in environment')
+ try:
-logging.info('reading config from %r', config_filename)
-config = load_config(config_filename, default_config)
+ config_filename = os.environ.get('ICK_CONTROLLER_CONFIG')
+ logging.info('config filename %r', config_filename)
+ if not config_filename:
+ logging.error('no ICK_CONTROLLER_CONFIG in environment')
+ raise Exception('No ICK_CONTROLLER_CONFIG defined in environment')
-logging.info('config is %r', config)
-ick2.setup_logging(config)
+ logging.info('reading config from %r', config_filename)
+ config = load_config(config_filename, default_config)
-ick2.log.log('info', msg_text='Ick2 controller starts', config=config)
+ logging.info('config is %r', config)
+ ick2.setup_logging(config)
-api = ick2.ControllerAPI()
-ick2.log.log('info', msg_text='created ControllerAPI')
+ ick2.log.log('info', msg_text='Ick2 controller starts', config=config)
-api.set_state_directory(config['statedir'])
-ick2.log.log('info', msg_text='called ControllerAPI.set_state_directory')
+ api = ick2.ControllerAPI()
+ ick2.log.log('info', msg_text='created ControllerAPI')
-api.load_projects()
-ick2.log.log('info', msg_text='called ControllerAPI.load_projects')
+ api.set_state_directory(config['statedir'])
+ ick2.log.log(
+ 'info', msg_text='called ControllerAPI.set_state_directory')
-app = apifw.create_bottle_application(api, counter, dict_logger, config)
-ick2.log.log('info', msg_text='called apifw.create_bottle_application')
+ api.load_projects()
+ ick2.log.log('info', msg_text='called ControllerAPI.load_projects')
+
+ application = apifw.create_bottle_application(
+ api, counter, dict_logger, config)
+ ick2.log.log('info', msg_text='called apifw.create_bottle_application')
+
+ return application
+ except SystemExit:
+ pass
+ except BaseException as e:
+ logging.error(str(e))
+ sys.exit(1)
+
+
+app = main()
# If we are running this program directly with Python, and not via
# gunicorn, we can use the Bottle built-in debug server, which can