setup_nginxuwsgi.py 1.0 KB

1234567891011121314151617181920212223242526
  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. subprocess.Popen(bin_dir + '/uwsgi --ini ' + config_dir + '/uwsgi.ini' +
  13. ' --processes ' + str(NCPU) +
  14. ' --wsgi hello:app',
  15. shell=True, cwd='wsgi',
  16. stdout=logfile, stderr=errfile)
  17. return 0
  18. except subprocess.CalledProcessError:
  19. return 1
  20. def stop(logfile, errfile):
  21. subprocess.call('sudo /usr/local/nginx/sbin/nginx -s stop', shell=True, stdout=logfile, stderr=errfile)
  22. subprocess.call(bin_dir + '/uwsgi --ini ' + config_dir + '/uwsgi_stop.ini', shell=True, stdout=logfile, stderr=errfile)
  23. return 0