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()