setup_nginx.py 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. import subprocess
  2. import sys
  3. import setup_util
  4. import os
  5. def start(args, logfile, errfile):
  6. if os.name == 'nt':
  7. return 1
  8. setup_util.replace_text("aspnet/src/Web.config", "localhost", args.database_host)
  9. try:
  10. # build
  11. subprocess.check_call("rm -rf bin obj", shell=True, cwd="aspnet", stderr=errfile, stdout=logfile)
  12. subprocess.check_call("xbuild /p:Configuration=Release", shell=True, cwd="aspnet/src", stderr=errfile, stdout=logfile)
  13. subprocess.check_call("sudo chown -R $USER:$USER $MONO_ROOT", shell=True, stderr=errfile, stdout=logfile)
  14. # nginx
  15. workers = 'worker_processes ' + str(args.max_threads) + ';'
  16. 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}" > $TROOT/nginx.upstream.conf', shell=True, stderr=errfile, stdout=logfile);
  17. subprocess.check_call('sudo /usr/local/nginx/sbin/nginx -c $TROOT/nginx.conf -g "' + workers + '"', shell=True, stderr=errfile, stdout=logfile)
  18. # fastcgi
  19. for port in range(9001, 9001 + args.max_threads):
  20. # /usr/local/bin/fastcgi-mono-server4
  21. subprocess.Popen("MONO_OPTIONS=--gc=sgen fastcgi-mono-server4 /applications=/:. /socket=tcp:127.0.0.1:" + str(port) + " &", shell=True, cwd="aspnet", stderr=errfile, stdout=logfile)
  22. return 0
  23. except subprocess.CalledProcessError:
  24. return 1
  25. def stop(logfile, errfile):
  26. if os.name == 'nt':
  27. return 0
  28. subprocess.check_call("sudo /usr/local/nginx/sbin/nginx -c $TROOT/nginx.conf -s stop", shell=True, stderr=errfile, stdout=logfile)
  29. subprocess.check_call("rm -f $TROOT/nginx.upstream.conf", shell=True, stderr=errfile, stdout=logfile)
  30. #
  31. # stop mono
  32. #
  33. p = subprocess.Popen(['ps', 'aux'], stdout=subprocess.PIPE)
  34. out, err = p.communicate()
  35. for line in out.splitlines():
  36. if 'mono-server' in line and not 'run-ci' in line and not 'run-tests' in line:
  37. pid = int(line.split(None, 2)[1])
  38. os.kill(pid, 15)
  39. return 0