setup_nginx.py 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  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. # build
  10. subprocess.check_call("rm -rf bin obj", shell=True, cwd="aspnet", stderr=errfile, stdout=logfile)
  11. subprocess.check_call("xbuild /p:Configuration=Release", shell=True, cwd="aspnet/src", stderr=errfile, stdout=logfile)
  12. subprocess.check_call("sudo chown -R $USER:$USER $MONO_ROOT", shell=True, stderr=errfile, stdout=logfile)
  13. # nginx
  14. workers = 'worker_processes ' + str(args.max_threads) + ';'
  15. logfile.write("Setting up workers as %s\n\n" % workers)
  16. subprocess.check_call("echo Hello there", shell=True, stderr=errfile, stdout=logfile);
  17. command = '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'
  18. logfile.write("Using command %s" % command)
  19. subprocess.check_call(command, shell=True, stderr=errfile, stdout=logfile);
  20. subprocess.check_call('sudo /usr/local/nginx/sbin/nginx -c $TROOT/nginx.conf -g "' + workers + '"', shell=True, stderr=errfile, stdout=logfile)
  21. # Start fastcgi for each thread
  22. # To debug, use --printlog --verbose --loglevels=All
  23. for port in range(9001, 9001 + args.max_threads):
  24. subprocess.Popen("MONO_OPTIONS=--gc=sgen fastcgi-mono-server4 --applications=/:%s/src --socket=tcp:127.0.0.1:%s " % (args.directory, port), shell=True, cwd="aspnet", stderr=errfile, stdout=logfile)
  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)