setup_nginx.py 1.1 KB

123456789101112131415161718192021222324252627
  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. def start(args, logfile, errfile):
  8. try:
  9. subprocess.check_call('sudo /usr/local/nginx/sbin/nginx -c ' +
  10. config_dir + '/nginx_uwsgi.conf', shell=True)
  11. # Run in the background, but keep stdout/stderr for easy debugging.
  12. # Note that this uses --gevent 1000 just like setup.py.
  13. subprocess.Popen(bin_dir + '/uwsgi --ini ' + config_dir + '/uwsgi.ini' +
  14. ' --processes ' + str(NCPU) +
  15. ' --gevent 1000 --wsgi hello',
  16. shell=True, cwd='uwsgi',
  17. stdout=logfile, stderr=errfile)
  18. return 0
  19. except subprocess.CalledProcessError:
  20. return 1
  21. def stop(logfile, errfile):
  22. subprocess.call('sudo /usr/local/nginx/sbin/nginx -s stop', shell=True, stdout=logfile, stderr=errfile)
  23. subprocess.call(bin_dir + '/uwsgi --ini ' + config_dir + '/uwsgi_stop.ini', shell=True, stdout=logfile, stderr=errfile)
  24. return 0