setup.py 891 B

12345678910111213141516171819202122232425262728
  1. import subprocess
  2. import multiprocessing
  3. import sys
  4. import setup_util
  5. import os
  6. from os.path import expanduser
  7. home = expanduser("~")
  8. def start(args):
  9. setup_util.replace_text("django/hello/hello/settings.py", "HOST': '.*'", "HOST': '" + args.database_host + "'")
  10. setup_util.replace_text("django/hello/hello/settings.py", "\/home\/ubuntu", home)
  11. subprocess.Popen("gunicorn hello.wsgi:application --worker-class=meinheld.gmeinheld.MeinheldWorker -b 0.0.0.0:8080 -w " +
  12. str((multiprocessing.cpu_count() * 3)) + " --log-level=critical", shell=True, cwd="django/hello")
  13. return 0
  14. def stop():
  15. p = subprocess.Popen(['ps', 'aux'], stdout=subprocess.PIPE)
  16. out, err = p.communicate()
  17. for line in out.splitlines():
  18. if 'gunicorn' in line:
  19. try:
  20. pid = int(line.split(None, 2)[1])
  21. os.kill(pid, 9)
  22. except OSError:
  23. pass
  24. return 0