ulib.sh 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. #!/bin/bash
  2. fw_depends gcc-4.9
  3. RETCODE=$(fw_exists ${IROOT}/ulib.installed)
  4. [ ! "$RETCODE" == 0 ] || { \
  5. source $IROOT/ulib.installed
  6. return 0; }
  7. ULIB_VERSION=1.4.2
  8. ULIB_ROOT=$IROOT/ULib
  9. ULIB_DOCUMENT_ROOT=$ULIB_ROOT/ULIB_DOCUMENT_ROOT
  10. # Create a run directory for ULIB
  11. [ ! -e $IROOT/ulib.installed -a -d $IROOT/ULib ] && rm -rf $IROOT/ULib*
  12. if [ ! -d "$ULIB_ROOT" ]; then
  13. mkdir -p $ULIB_ROOT
  14. fi
  15. # AVOID "fatal error: postgres_fe.h: No such file or directory"
  16. # TODO: This should already be installed and unnecessary.
  17. sudo apt-get install -y postgresql-server-dev-all
  18. # make use of FIFO scheduling policy possible (we must avoid use of test because bash signal trapping)
  19. #type setcap >/dev/null 2>/dev/null
  20. #if [ $? -ne 0 ]; then
  21. sudo apt-get install -y libcap2-bin
  22. #fi
  23. # We need to install mongo-c-driver (we don't have a ubuntu package)
  24. RETCODE=$(fw_exists ${IROOT}/mongo-c-driver.installed)
  25. if [ "$RETCODE" != 0 ]; then
  26. wget https://github.com/mongodb/mongo-c-driver/releases/download/1.1.10/mongo-c-driver-1.1.10.tar.gz
  27. tar -xzf mongo-c-driver-1.1.10.tar.gz
  28. cd mongo-c-driver-1.1.10/
  29. ./configure --prefix=$IROOT --libdir=$IROOT
  30. make && sudo make install
  31. touch ${IROOT}/mongo-c-driver.installed
  32. fi
  33. # Add a simple configuration file to it
  34. cd $ULIB_ROOT
  35. if [ ! -f "benchmark.cfg" ]; then
  36. cat <<EOF >benchmark.cfg
  37. userver {
  38. PORT 8080
  39. PREFORK_CHILD 4
  40. TCP_LINGER_SET -1
  41. LISTEN_BACKLOG 256
  42. ORM_DRIVER "mysql pgsql sqlite"
  43. DOCUMENT_ROOT $ULIB_DOCUMENT_ROOT
  44. }
  45. EOF
  46. fi
  47. # 1. Download ULib
  48. cd $IROOT
  49. fw_get -o ULib-${ULIB_VERSION}.tar.gz https://github.com/stefanocasazza/ULib/archive/v${ULIB_VERSION}.tar.gz
  50. fw_untar ULib-${ULIB_VERSION}.tar.gz
  51. # 2. Compile application (userver_tcp)
  52. cd ULib-$ULIB_VERSION
  53. # Check for the compiler support (We want at least g++ 4.8)
  54. CC=gcc # C compiler command
  55. CXX=g++ # C++ compiler command
  56. gcc_version=`g++ -dumpversion`
  57. case "$gcc_version" in
  58. 3*|4.0*|4.1*|4.2*|4.3*|4.4*|4.5*|4.6*|4.7*|4.8*)
  59. CC='gcc-4.9'
  60. CXX='g++-4.9'
  61. ;;
  62. esac
  63. export CC CXX
  64. # AVOID "configure: error: newly created file is older than distributed files! Check your system clock"
  65. find . -exec touch {} \;
  66. USP_FLAGS="-DAS_cpoll_cppsp_DO" \
  67. ./configure --prefix=$ULIB_ROOT \
  68. --disable-static --disable-examples \
  69. --with-mysql --with-pgsql --with-sqlite3 \
  70. --without-ssl --without-pcre --without-expat \
  71. --without-libz --without-libuuid --without-magic --without-libares \
  72. --enable-static-orm-driver='mysql pgsql sqlite' --enable-static-server-plugin=http \
  73. --with-mongodb --with-mongodb-includes="-I$IROOT/include/libbson-1.0 -I$IROOT/include/libmongoc-1.0" --with-mongodb-ldflags="-L$IROOT"
  74. # --enable-debug \
  75. #USP_LIBS="-ljson" \
  76. make install
  77. cp -r tests/examples/benchmark/FrameworkBenchmarks/ULib/db $ULIB_ROOT
  78. cd examples/userver
  79. make install
  80. # 3. Compile usp pages for benchmark (no more REDIS)
  81. cd ../../src/ulib/net/server/plugin/usp
  82. make json.la plaintext.la db.la query.la update.la fortune.la \
  83. mdb.la mquery.la mupdate.la mfortune.la
  84. # rdb.la rquery.la rupdate.la rfortune.la
  85. # Check that compilation worked
  86. if [ ! -e .libs/db.so ]; then
  87. exit 1
  88. fi
  89. mkdir -p $ULIB_DOCUMENT_ROOT
  90. cp .libs/json.so .libs/plaintext.so \
  91. .libs/db.so .libs/query.so .libs/update.so .libs/fortune.so \
  92. .libs/mdb.so .libs/mquery.so .libs/mupdate.so .libs/mfortune.so $ULIB_DOCUMENT_ROOT
  93. # .libs/rdb.so .libs/rquery.so .libs/rupdate.so .libs/rfortune.so \
  94. echo "export ULIB_VERSION=${ULIB_VERSION}" >> $IROOT/ulib.installed
  95. echo "export ULIB_ROOT=${ULIB_ROOT}" >> $IROOT/ulib.installed
  96. echo "export ULIB_DOCUMENT_ROOT=${ULIB_DOCUMENT_ROOT}" >> $IROOT/ulib.installed
  97. echo -e "export PATH=\$ULIB_ROOT/bin:\$PATH" >> $IROOT/ulib.installed
  98. source $IROOT/ulib.installed