setup_libevent.py 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. import subprocess
  2. import sys
  3. import setup_util
  4. import os
  5. root = os.getcwd() + "/nancy"
  6. app = root + "/src"
  7. def start(args, logfile, errfile):
  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, stderr=errfile, stdout=logfile)
  14. subprocess.check_call("xbuild /p:Configuration=Release", shell=True, cwd=app, stderr=errfile, stdout=logfile)
  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, stderr=errfile, stdout=logfile);
  18. subprocess.check_call('sudo /usr/local/nginx/sbin/nginx -c ' + root + '/nginx.conf.libevent -g "' + workers + '"', shell=True, stderr=errfile, stdout=logfile)
  19. # fastcgi
  20. os.environ['MONO_GC_PARAMS']="nursery-size=16m"
  21. for port in range(9001, 9001 + args.max_threads):
  22. subprocess.Popen("mono-sgen -O=all LibeventHost/bin/Release/LibeventHost.exe 127.0.0.1 " + str(port) + " " + args.database_host + " &", shell=True, cwd=app, stderr=errfile, stdout=logfile)
  23. return 0
  24. except subprocess.CalledProcessError:
  25. return 1
  26. def stop(logfile, errfile):
  27. if os.name == 'nt':
  28. return 0
  29. subprocess.check_call("sudo /usr/local/nginx/sbin/nginx -c " + root + "/nginx.conf -s stop", shell=True, stderr=errfile, stdout=logfile)
  30. subprocess.check_call("rm -f " + root + "/nginx.upstream.conf", shell=True, stderr=errfile, stdout=logfile)
  31. subprocess.check_call("pkill -9 mono-sgen", shell=True, stderr=errfile, stdout=logfile)
  32. return 0