setup_nginx.sh 1.3 KB

123456789101112131415161718192021222324252627282930313233343536
  1. #!/bin/bash
  2. fw_depends mysql nginx mono
  3. sed -i 's|localhost|'"${DBHOST}"'|g' src/Web.config
  4. sed -i 's|include /usr/local/nginx/conf/fastcgi_params;|include '"${NGINX_HOME}"'/conf/fastcgi_params;|g' nginx.conf
  5. # build
  6. rm -rf src/bin src/obj
  7. xbuild src/NancyBenchmark.csproj /t:Clean
  8. xbuild src/NancyBenchmark.csproj /p:Configuration=Release
  9. # nginx
  10. port_start=9001
  11. port_end=$((${port_start}+${MAX_THREADS}))
  12. conf="upstream mono {\n"
  13. for port in $(seq ${port_start} $port_end); do
  14. conf+="\tserver 127.0.0.1:${port};\n"
  15. done
  16. conf+="}"
  17. # Store path of fastcgi_params dynamically in a file called "nginx.osenv.conf".
  18. # The reason why I do this is Ngix "include" cannot recognize variables. (Well known issue of Nginx)
  19. # To use OS Environment at ngix.conf 3rd party library or perl module is needed
  20. # Current approach is one trick to solve the problem without utilize those 3rd party libraries.
  21. echo "include $IROOT/nginx/conf/fastcgi_params;" > $TROOT/nginx.osenv.conf
  22. echo -e $conf > $TROOT/nginx.upstream.conf
  23. ${NGINX_HOME}/sbin/nginx -c $TROOT/nginx.conf -g "worker_processes '"${MAX_THREADS}"';"
  24. # Start fastcgi for each thread
  25. # To debug, use --printlog --verbose --loglevels=All
  26. for port in $(seq ${port_start} $port_end); do
  27. MONO_OPTIONS=--gc=sgen fastcgi-mono-server4 --applications=/:$TROOT/src --socket=tcp:127.0.0.1:$port &
  28. done