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.0KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  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. ##@brief uwsgi startup demo
  14. @LodelHook('lodel2_loader_main')
  15. def uwsgi_fork(hook_name, caller, payload):
  16. standalone = Settings.webui.standalone
  17. if standalone.lower() == 'false':
  18. return
  19. else:
  20. sockfile = os.path.join(buildconf.LODEL2VARDIR, 'uwsgi_sockets/')
  21. if not os.path.isdir(sockfile):
  22. os.mkdir(sockfile)
  23. sockfile = os.path.join(sockfile,
  24. Settings.sitename.replace('/','_') + '.sock')
  25. logfile = os.path.join(
  26. buildconf.LODEL2LOGDIR, 'uwsgi_%s.log' % (
  27. Settings.sitename.replace('/', '_')))
  28. if standalone.lower() == 'true':
  29. cmd='{uwsgi} --http-socket {addr}:{port} --module \
  30. plugins.webui.run --socket {sockfile} --logto {logfile}'
  31. cmd = cmd.format(
  32. addr = Settings.webui.listen_address,
  33. port = Settings.webui.listen_port,
  34. uwsgi= Settings.webui.uwsgicmd,
  35. sockfile=sockfile,
  36. logfile = logfile)
  37. if Settings.webui.virtualenv is not None:
  38. cmd += " --virtualenv %s" % Settings.webui.virtualenv
  39. elif Settings.webui.standalone == 'uwsgi':
  40. cmd = '{uwsgi} --ini ./plugins/webui/uwsgi/uwsgi.ini \
  41. --socket {sockfile} --logto {logfile}'
  42. cmd = cmd.format(uwsgi = Settings.webui.uwsgicmd,
  43. sockfile = sockfile, logfile = logfile)
  44. try:
  45. args = shlex.split(cmd)
  46. exit(os.execl(args[0], *args))
  47. except Exception as e:
  48. print("Webui plugin uwsgi execl fails cmd was '%s' error : " % cmd,
  49. e, file=sys.stderr)
  50. exit(1)