setup_nginxuwsgi.py 1.2 KB

123456789101112131415161718192021222324252627282930313233343536
  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.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(
  15. "{0}/uwsgi --ini {1}/uwsgi.ini --processes {2} --env DBHOSTNAME={3} --wsgi app:app".format(
  16. bin_dir, config_dir, NCPU*3, args.database_host),
  17. shell=True, cwd='bottle', stderr=errfile, stdout=logfile)
  18. return 0
  19. except subprocess.CalledProcessError:
  20. return 1
  21. def stop(logfile, errfile):
  22. subprocess.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',
  26. shell=True, stderr=errfile, stdout=logfile)
  27. return 0