From 2c836046a61b4132d090848620307136caa06540 Mon Sep 17 00:00:00 2001 From: Sunil Mohan Adapa Date: Fri, 12 Feb 2016 14:00:47 +0530 Subject: [PATCH] main: Add command argument to setup essential apps - The --setup argument sets up all applications that declare themselves as essential. - This is done synchronously. - Plinth exits after the setup is complete. - Plinth fails with an error in case any of the setup tasks fail. The process will be continued on next invocation or access of application from UI. --- plinth/__main__.py | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/plinth/__main__.py b/plinth/__main__.py index af4a82d5b..6b463d272 100644 --- a/plinth/__main__.py +++ b/plinth/__main__.py @@ -33,6 +33,7 @@ from cherrypy.process.plugins import Daemonizer from plinth import cfg from plinth import module_loader from plinth import service +from plinth import setup logger = logging.getLogger(__name__) @@ -57,6 +58,9 @@ def parse_arguments(): parser.add_argument( '--no-daemon', action='store_true', default=cfg.no_daemon, help='do not start as a daemon') + parser.add_argument( + '--setup', action='store_true', default=False, + help='run setup tasks on all essential modules and exit') parser.add_argument( '--diagnose', action='store_true', default=False, help='run diagnostic tests and exit') @@ -277,6 +281,18 @@ def configure_django(): os.chmod(cfg.store_file, stat.S_IRUSR | stat.S_IWUSR | stat.S_IRGRP) +def run_setup_and_exit(): + """Run setup on all essential modules and exit.""" + error_code = 0 + try: + setup.setup_all_modules(essential=True) + except Exception as exception: + logger.error('Error running setup - %s', exception) + error_code = 1 + + sys.exit(error_code) + + def run_diagnostics_and_exit(): """Run diagostics on all modules and exit.""" module = importlib.import_module('plinth.modules.diagnostics.diagnostics') @@ -314,6 +330,9 @@ def main(): module_loader.load_modules() + if arguments.setup: + run_setup_and_exit() + if arguments.diagnose: run_diagnostics_and_exit()