No Description
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

loader.py 1.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. # -*- coding: utf-8 -*-
  2. import os
  3. import sys
  4. import shlex
  5. import warnings
  6. ##@brief Preloader for a multisite process
  7. #
  8. #This loader is a kind of fake loader. In fact it only read configurations
  9. #for the multisite instance and then run a UWSGI process that will run
  10. #the run.py file.
  11. #
  12. #If you want to see the "real" multisite loading process see
  13. #@ref lodel/plugins/multisite/run.py file
  14. #
  15. #@par Implementation details
  16. #Here we have to bootstrap a minimal __loader__ context in order
  17. #to be able to load the settings
  18. #
  19. #This file (once bootstraped) start a new process for uWSGI. uWSGI then
  20. #run lodel.plugins.multisite.run.application function
  21. #@note the uwsgi process in started using the execl function when UWSGI
  22. #will exit this process will stop too
  23. #
  24. from lodel import buildconf
  25. from lodel import bootstrap
  26. bootstrap.bootstrap('__loader__')
  27. try:
  28. from lodel.context import LodelContext
  29. except ImportError:
  30. LODEL_BASE_DIR = os.path.dirname(
  31. os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
  32. from lodel.context import LodelContext
  33. LodelContext.expose_modules(globals(), {
  34. 'lodel.plugin.hooks': ['LodelHook'],
  35. })
  36. #If an interface that execl to run was loaded it will be run by following
  37. #hook
  38. LodelHook.call_hook('multisite_execl_interface', '__main__', None)
  39. #Nothing appened, running default ipython interface
  40. #The interface as to be run by execl to go out of this partial context
  41. PYTHON_EXC = '/usr/bin/python3'
  42. RUNNER_FILE = os.path.join(
  43. os.path.dirname(os.path.realpath(__file__)),
  44. 'run.py')
  45. cmd = '%s "%s"' % (PYTHON_EXC, RUNNER_FILE)
  46. try:
  47. args = shlex.split(cmd)
  48. print("\n\nEND LOADER MULTISITE, execl\n\n")
  49. exit(os.execl(args[0], *args))
  50. except Exception as e:
  51. print("Multisite std interface execl fails. Command was : '%s' error \
  52. : %s" % (cmd, e), file=sys.stderr)
  53. exit(1)