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.

main.py 2.2KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. #-*- coding: utf-8 -*-
  2. import os, os.path
  3. import sys
  4. import shlex
  5. from lodel.plugin import LodelHook
  6. from lodel.settings import Settings
  7. from lodel import buildconf
  8. PLUGIN_PATH = os.path.dirname(__file__)
  9. ##@brief Return the root url of the instance
  10. #@warning no trailing slash
  11. def root_url():
  12. return Settings.sitename
  13. def static_url():
  14. return Settings.webui.static_url
  15. ##@brief uwsgi startup demo
  16. @LodelHook('lodel2_loader_main')
  17. def uwsgi_fork(hook_name, caller, payload):
  18. standalone = Settings.webui.standalone
  19. if standalone.lower() == 'false':
  20. return
  21. else:
  22. sockfile = os.path.join(buildconf.LODEL2VARDIR, 'uwsgi_sockets/')
  23. if not os.path.isdir(sockfile):
  24. os.mkdir(sockfile)
  25. sockfile = os.path.join(sockfile,
  26. Settings.sitename.replace('/','_') + '.sock')
  27. logfile = os.path.join(
  28. buildconf.LODEL2LOGDIR, 'uwsgi_%s.log' % (
  29. Settings.sitename.replace('/', '_')))
  30. if standalone.lower() == 'true':
  31. cmd='{uwsgi} --plugin python3 --http-socket {addr}:{port} --module \
  32. plugins.webui.run --socket {sockfile} --logto {logfile} -p {uwsgiworkers}'
  33. cmd = cmd.format(
  34. addr = Settings.webui.listen_address,
  35. port = Settings.webui.listen_port,
  36. uwsgi= Settings.webui.uwsgicmd,
  37. sockfile=sockfile,
  38. logfile = logfile,
  39. uwsgiworkers = Settings.webui.uwsgi_workers)
  40. if Settings.webui.virtualenv is not None:
  41. cmd += " --virtualenv %s" % Settings.webui.virtualenv
  42. elif Settings.webui.standalone == 'uwsgi':
  43. cmd = '{uwsgi} --plugin python3 --ini ./plugins/webui/uwsgi/uwsgi.ini \
  44. --socket {sockfile} --logto {logfile} -p {uwsgiworkers}'
  45. cmd = cmd.format(uwsgi = Settings.webui.uwsgicmd,
  46. sockfile = sockfile, logfile = logfile, uwsgiworkers=Settings.webui.uwsgi_workers)
  47. try:
  48. args = shlex.split(cmd)
  49. exit(os.execl(args[0], *args))
  50. except Exception as e:
  51. print("Webui plugin uwsgi execl fails cmd was '%s' error : " % cmd,
  52. e, file=sys.stderr)
  53. exit(1)