setup_nginx.py 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. import subprocess
  2. import sys
  3. import setup_util
  4. import os
  5. root = os.getcwd() + "/aspnet"
  6. app = root + "/src"
  7. def start(args):
  8. if os.name == 'nt':
  9. return 1
  10. setup_util.replace_text(app + "/Web.config", "localhost", args.database_host)
  11. try:
  12. # build
  13. subprocess.check_call("rm -rf bin obj", shell=True, cwd=app)
  14. subprocess.check_call("xbuild /p:Configuration=Release", shell=True, cwd=app)
  15. # nginx
  16. workers = 'worker_processes ' + str(args.max_threads) + ';'
  17. 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);
  18. subprocess.check_call('sudo /usr/local/nginx/sbin/nginx -c ' + root + '/nginx.conf -g "' + workers + '"', shell=True)
  19. # fastcgi
  20. for port in range(9001, 9001 + args.max_threads):
  21. subprocess.Popen("fastcgi-mono-server4 /applications=/:. /socket=tcp:127.0.0.1:" + str(port) + " &", shell=True, cwd=app)
  22. return 0
  23. except subprocess.CalledProcessError:
  24. return 1
  25. def stop():
  26. if os.name == 'nt':
  27. return 0
  28. subprocess.check_call("sudo /usr/local/nginx/sbin/nginx -c " + root + "/nginx.conf -s stop", shell=True)
  29. subprocess.check_call("rm -f " + root + "/nginx.upstream.conf", shell=True)
  30. subprocess.check_call("pkill -9 mono", shell=True)
  31. return 0