Brak opisu
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 2.4KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  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. try:
  25. from lodel.context import LodelContext
  26. except ImportError:
  27. LODEL_BASE_DIR = os.path.dirname(
  28. os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
  29. from lodel.context import LodelContext
  30. from lodel import buildconf
  31. LodelContext.init(LodelContext.MULTISITE)
  32. LodelContext.set(None) #Loading context creation
  33. #Multisite instance settings loading
  34. CONFDIR = os.path.join(os.getcwd(), 'server_conf.d')
  35. if not os.path.isdir(CONFDIR):
  36. warnings.warn('%s do not exists, default settings used' % CONFDIR)
  37. LodelContext.expose_modules(globals(), {
  38. 'lodel.settings.settings': [('Settings', 'settings')],
  39. 'lodel.plugins.multisite.confspecs': 'multisite_confspecs'})
  40. if not settings.started():
  41. settings('./server_conf.d', multisite_confspecs.LODEL2_CONFSPECS)
  42. LodelContext.expose_modules(globals(), {
  43. 'lodel.settings': ['Settings']})
  44. print(Settings.lodelsites)
  45. LodelContext.expose_modules(globals(), {
  46. 'lodel.plugin.hooks': ['LodelHook'],
  47. })
  48. #If an interface that execl to run was loaded it will be run by following
  49. #hook
  50. LodelHook.call_hook('multisite_execl_interface', '__main__', None)
  51. #Nothing appened, running default ipython interface
  52. #The interface as to be run by execl to go out of this partial context
  53. PYTHON_EXC = '/usr/bin/python3'
  54. RUNNER_FILE = os.path.join(
  55. os.path.dirname(os.path.realpath(__file__)),
  56. 'run.py')
  57. cmd = '%s "%s"' % (PYTHON_EXC, RUNNER_FILE)
  58. try:
  59. args = shlex.split(cmd)
  60. print("\n\nEND LOADER MULTISITE, execl\n\n")
  61. exit(os.execl(args[0], *args))
  62. except Exception as e:
  63. print("Multisite std interface execl fails. Command was : '%s' error \
  64. : %s" % (cmd, e), file=sys.stderr)
  65. exit(1)