setup-nginx.py 1.3 KB

123456789101112131415161718192021222324252627282930313233
  1. import subprocess
  2. import sys
  3. import setup_util
  4. import os
  5. root = os.getcwd() + "/aspnet-mono"
  6. app = root + "/project/Benchmarks.Mono.AspNet"
  7. def start(args):
  8. setup_util.replace_text(app + "/Web.config", "localhost", args.database_host)
  9. try:
  10. # build
  11. subprocess.check_call("rm -rf bin obj", shell=True, cwd=app)
  12. subprocess.check_call("xbuild", shell=True, cwd=app)
  13. # nginx
  14. workers = 'worker_processes ' + str(args.max_threads) + ';'
  15. subprocess.check_call('echo "upstream mono {\n' + ';\n'.join('\tserver 127.0.0.1:' + str(port) for port in range(9001, 9001 + args.max_threads)) + ';\n}" > ' + root + '/nginx.upstream.conf', shell=True);
  16. subprocess.check_call('sudo /usr/local/nginx/sbin/nginx -c ' + root + '/nginx.conf -g "' + workers + '"', shell=True)
  17. # fastcgi
  18. for port in range(9001, 9001 + args.max_threads):
  19. subprocess.Popen("fastcgi-mono-server4 /applications=/:. /socket=tcp:127.0.0.1:" + str(port) + " &", shell=True, cwd=app)
  20. return 0
  21. except subprocess.CalledProcessError:
  22. return 1
  23. def stop():
  24. subprocess.check_call("sudo /usr/local/nginx/sbin/nginx -c " + root + "/nginx.conf -s stop", shell=True)
  25. subprocess.check_call("rm -f " + root + "/nginx.upstream.conf", shell=True)
  26. subprocess.check_call("pkill -9 mono", shell=True)
  27. return 0