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.
This commit is contained in:
Sunil Mohan Adapa 2016-02-12 14:00:47 +05:30
parent 8dcafe3e0e
commit 2c836046a6
No known key found for this signature in database
GPG Key ID: 36C361440C9BC971

View File

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