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 3.1KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. #
  2. # This file is part of Lodel 2 (https://github.com/OpenEdition)
  3. #
  4. # Copyright (C) 2015-2017 Cléo UMS-3287
  5. #
  6. # This program is free software: you can redistribute it and/or modify
  7. # it under the terms of the GNU Affero General Public License as published
  8. # by the Free Software Foundation, either version 3 of the License, or
  9. # (at your option) any later version.
  10. #
  11. # This program is distributed in the hope that it will be useful,
  12. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. # GNU Affero General Public License for more details.
  15. #
  16. # You should have received a copy of the GNU Affero General Public License
  17. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  18. #
  19. import os
  20. import sys
  21. import shlex
  22. import warnings
  23. #Here we have to bootstrap a minimal __loader__ context in order
  24. #to be able to load the settings
  25. #
  26. #This file (once bootstraped) start a new process for uWSGI. uWSGI then
  27. #run lodel.plugins.multisite.run.application function
  28. try:
  29. from lodel.context import LodelContext
  30. except ImportError:
  31. LODEL_BASE_DIR = os.path.dirname(
  32. os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
  33. from lodel.context import LodelContext
  34. from lodel import buildconf
  35. LodelContext.init(LodelContext.MULTISITE)
  36. LodelContext.set(None) #Loading context creation
  37. #Multisite instance settings loading
  38. CONFDIR = os.path.join(os.getcwd(), 'conf.d')
  39. if not os.path.isdir(CONFDIR):
  40. warnings.warn('%s do not exists, default settings used' % CONFDIR)
  41. LodelContext.expose_modules(globals(), {
  42. 'lodel.settings.settings': [('Settings', 'settings')],
  43. 'lodel.plugins.multisite.confspecs': 'multisite_confspecs'})
  44. if not settings.started():
  45. settings('./conf.d', multisite_confspecs.LODEL2_CONFSPECS)
  46. LodelContext.expose_modules(globals(), {
  47. 'lodel.settings': ['Settings']})
  48. ##@brief Starts uwsgi in background using settings
  49. def uwsgi_fork():
  50. sockfile = os.path.join(buildconf.LODEL2VARDIR, 'uwsgi_sockets/')
  51. if not os.path.isdir(sockfile):
  52. os.mkdir(sockfile)
  53. sockfile = os.path.join(sockfile, 'uwsgi_lodel2_multisite.sock')
  54. logfile = os.path.join(
  55. buildconf.LODEL2LOGDIR, 'uwsgi_lodel2_multisite.log')
  56. cmd='{uwsgi} --plugin python3 --http-socket {addr}:{port} --module \
  57. lodel.plugins.multisite.run --socket {sockfile} --logto {logfile} -p {uwsgiworkers}'
  58. cmd = cmd.format(
  59. addr = Settings.server.listen_address,
  60. port = Settings.server.listen_port,
  61. uwsgi= Settings.server.uwsgicmd,
  62. sockfile=sockfile,
  63. logfile = logfile,
  64. uwsgiworkers = Settings.server.uwsgi_workers)
  65. if Settings.server.virtualenv is not None:
  66. cmd += " --virtualenv %s" % Settings.webui.virtualenv
  67. try:
  68. args = shlex.split(cmd)
  69. print("Running %s" % cmd)
  70. exit(os.execl(args[0], *args))
  71. except Exception as e:
  72. print("Webui plugin uwsgi execl fails cmd was '%s' error : " % cmd,
  73. e, file=sys.stderr)
  74. exit(1)
  75. if __name__ == '__main__':
  76. uwsgi_fork()