setup.py 1.1 KB

1234567891011121314151617181920212223242526272829
  1. import subprocess
  2. import sys
  3. import setup_util
  4. import os
  5. from os.path import expanduser
  6. home = expanduser("~")
  7. def start(args):
  8. setup_util.replace_text("django/hello/hello/settings.py", "HOST': '.*'", "HOST': '" + args.database_host + "'")
  9. setup_util.replace_text("django/hello/hello/settings.py", "\/home\/ubuntu", home)
  10. # because pooling doesn't work with meinheld, it's necessary to create a ton of gunicorn threads (think apache pre-fork)
  11. # to allow the OS to switch processes when waiting for socket I/O.
  12. args.max_threads *= 8
  13. # and go from there until the database server runs out of memory for new threads (connections)
  14. subprocess.Popen("gunicorn hello.wsgi:application --worker-class=\"egg:meinheld#gunicorn_worker\" -b 0.0.0.0:8080 -w " + str((args.max_threads * 2)) + " --log-level=critical", shell=True, cwd="django/hello")
  15. return 0
  16. def stop():
  17. p = subprocess.Popen(['ps', 'aux'], stdout=subprocess.PIPE)
  18. out, err = p.communicate()
  19. for line in out.splitlines():
  20. if 'gunicorn' in line:
  21. try:
  22. pid = int(line.split(None, 2)[1])
  23. os.kill(pid, 9)
  24. except OSError:
  25. pass
  26. return 0