ulib.sh 3.6 KB

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