setup.py 837 B

12345678910111213141516171819202122232425
  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. 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")
  11. return 0
  12. def stop():
  13. p = subprocess.Popen(['ps', 'aux'], stdout=subprocess.PIPE)
  14. out, err = p.communicate()
  15. for line in out.splitlines():
  16. if 'gunicorn' in line:
  17. try:
  18. pid = int(line.split(None, 2)[1])
  19. os.kill(pid, 9)
  20. except OSError:
  21. pass
  22. return 0