setup_nginxuwsgi.py 1.2 KB

123456789101112131415161718192021222324252627282930313233343536
  1. import subprocess
  2. import multiprocessing
  3. import os
  4. import setup_util
  5. bin_dir = os.path.expanduser('~/FrameworkBenchmarks/installs/py2/bin')
  6. config_dir = os.path.expanduser('~/FrameworkBenchmarks/config')
  7. NCPU = multiprocessing.cpu_count()
  8. NGINX_COMMAND = '/usr/local/nginx/sbin/nginx -c ' + config_dir + '/nginx_uwsgi.conf'
  9. def start(args, logfile, errfile):
  10. setup_util.replace_text("flask/app.py", "DBHOSTNAME", args.database_host)
  11. try:
  12. subprocess.call(
  13. NGINX_COMMAND,
  14. shell=True, stdout=logfile, stderr=errfile)
  15. # Run in the background, but keep stdout/stderr for easy debugging
  16. subprocess.Popen(bin_dir + '/uwsgi --ini ' + config_dir + '/uwsgi.ini' +
  17. ' --processes ' + str(NCPU * 3) +
  18. ' --wsgi app:app',
  19. shell=True, cwd='flask', stderr=errfile, stdout=logfile)
  20. return 0
  21. except subprocess.CalledProcessError:
  22. return 1
  23. def stop(logfile, errfile):
  24. subprocess.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, stderr=errfile, stdout=logfile)
  28. os.system('killall nginx')
  29. os.system('killall uwsgi')
  30. return 0