setup_nginx.py 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. import subprocess
  2. import multiprocessing
  3. import os
  4. bin_dir = os.path.expanduser('~/FrameworkBenchmarks/installs/py2/bin')
  5. config_dir = os.path.expanduser('~/FrameworkBenchmarks/config')
  6. NCPU = multiprocessing.cpu_count()
  7. NGINX_COMMAND = 'sudo /usr/local/nginx/sbin/nginx -c ' + config_dir + '/nginx_uwsgi.conf'
  8. def start(args, logfile, errfile):
  9. try:
  10. subprocess.check_call(
  11. NGINX_COMMAND,
  12. shell=True, stdout=logfile, stderr=errfile)
  13. # Run in the background, but keep stdout/stderr for easy debugging.
  14. # Note that this uses --gevent 1000 just like setup.py.
  15. subprocess.Popen(bin_dir + '/uwsgi --ini ' + config_dir + '/uwsgi.ini' +
  16. ' --processes ' + str(NCPU) +
  17. ' --gevent 1000 --wsgi hello',
  18. shell=True, cwd='uwsgi',
  19. stdout=logfile, stderr=errfile)
  20. return 0
  21. except subprocess.CalledProcessError:
  22. return 1
  23. def stop(logfile, errfile):
  24. subprocess.check_call(
  25. NGINX_COMMAND + ' -s stop',
  26. shell=True, stdout=logfile, stderr=errfile)
  27. subprocess.call(bin_dir + '/uwsgi --ini ' + config_dir + '/uwsgi_stop.ini', shell=True, stdout=logfile, stderr=errfile)
  28. os.system('killall nginx')
  29. os.system('killall uwsgi')
  30. return 0