setup_nginxuwsgi.py 1.2 KB

12345678910111213141516171819202122232425262728293031323334
  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 = '/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. subprocess.Popen(bin_dir + '/uwsgi --ini ' + config_dir + '/uwsgi.ini' +
  15. ' --processes ' + str(NCPU) +
  16. ' --wsgi hello:app',
  17. shell=True, cwd='wsgi', stdout=logfile, stderr=errfile)
  18. return 0
  19. except subprocess.CalledProcessError:
  20. return 1
  21. def stop(logfile, errfile):
  22. subprocess.check_call(
  23. NGINX_COMMAND + ' -s stop',
  24. shell=True, stdout=logfile, stderr=errfile)
  25. subprocess.call(bin_dir + '/uwsgi --ini ' + config_dir + '/uwsgi_stop.ini', shell=True, stdout=logfile, stderr=errfile)
  26. os.system('killall nginx')
  27. os.system('killall uwsgi')
  28. return 0