setup_pg.py 958 B

12345678910111213141516171819202122232425262728293031323334353637
  1. import subprocess
  2. import setup_util
  3. import multiprocessing
  4. import os
  5. home = os.path.expanduser('~')
  6. bin_dir = os.path.expanduser('~/FrameworkBenchmarks/installs/py2/bin')
  7. NCPU = multiprocessing.cpu_count()
  8. proc = None
  9. def start(args):
  10. global proc
  11. setup_util.replace_text("django/hello/hello/settings.py", "HOST': '.*'", "HOST': '" + args.database_host + "'")
  12. setup_util.replace_text("django/hello/hello/settings.py", "\/home\/ubuntu", home)
  13. env = os.environ.copy()
  14. env['DJANGO_DB'] = 'postgresql_psycopg2'
  15. proc = subprocess.Popen([
  16. bin_dir + "/gunicorn",
  17. "hello.wsgi:application",
  18. "-k", "meinheld.gmeinheld.MeinheldWorker",
  19. "-b", "0.0.0.0:8080",
  20. '-w', str(NCPU*3),
  21. "--log-level=critical"],
  22. cwd="django/hello",
  23. env=env)
  24. return 0
  25. def stop():
  26. global proc
  27. if proc is None:
  28. return 0
  29. proc.terminate()
  30. proc.wait()
  31. proc = None
  32. return 0