setup.sh 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. #!/bin/bash
  2. sed -i 's|host: .*|host: '"${DBHOST}"'|g' postgresql.yaml
  3. sed -i 's|host: .*|host: '"${DBHOST}"'|g' mongodb.yaml
  4. fw_depends dart nginx
  5. pub upgrade
  6. #
  7. # start dart servers
  8. #
  9. current=9001
  10. end=$(($current+$CPU_COUNT))
  11. while [ $current -lt $end ]; do
  12. dart server.dart -a 127.0.0.1 -p $current -d ${CPU_COUNT} &
  13. let current=current+1
  14. done
  15. #
  16. # create nginx configuration
  17. #
  18. conf+="worker_processes ${CPU_COUNT};\n"
  19. conf+="error_log /dev/null error;\n"
  20. conf+="events {\n"
  21. conf+="\tworker_connections 1024;\n"
  22. conf+="}\n"
  23. conf+="http {\n"
  24. conf+="\taccess_log off;\n"
  25. conf+="\tinclude ${NGINX_HOME}/conf/mime.types;\n"
  26. conf+="\tdefault_type application/octet-stream;\n"
  27. conf+="\tsendfile on;\n"
  28. conf+="\tupstream dart_cluster {\n"
  29. current=9001
  30. end=$(($current+$CPU_COUNT))
  31. while [ $current -lt $end ]; do
  32. conf+="\t\tserver 127.0.0.1:${current};\n"
  33. let current=current+1
  34. done
  35. conf+="\t\tkeepalive ${CPU_COUNT};\n"
  36. conf+="\t}\n"
  37. conf+="\tserver {\n"
  38. conf+="\t\tlisten 8080;\n"
  39. conf+="\t\tlocation / {\n"
  40. conf+="\t\t\tproxy_pass http://dart_cluster;\n"
  41. conf+="\t\t\tproxy_http_version 1.1;\n"
  42. conf+="\t\t\tproxy_set_header Connection \"\";\n"
  43. conf+="\t\t}\n"
  44. conf+="\t}\n"
  45. conf+="}"
  46. #
  47. # write nginx configuration to disk
  48. #
  49. echo -e $conf > nginx.conf
  50. nginx -c $(pwd)/nginx.conf &