Browse Source

Clean up ULib framework

Most of the extra stuff was added because IROOT/TROOT were
not being properly made available! Minor changes were because
some behavior was duplicating pre-existing TFB code, and because
we want all framework stdout/stderr to be handled in the same
manner for future changes.

Closes #943
Hamilton Turner 11 years ago
parent
commit
8b10681ffb
3 changed files with 42 additions and 179 deletions
  1. 1 3
      ULib/bash_profile.sh
  2. 31 15
      ULib/install.sh
  3. 10 161
      ULib/setup.py

+ 1 - 3
ULib/bash_profile.sh

@@ -12,7 +12,5 @@
 #    . $FWROOT/ULib/install.sh (cwd=$FWROOT//installs)
 #---------------------------------------------------------------------------------------------------------
 export ULIB_VERSION=1.4.1
-export ULIB_ROOT=${IROOT}/ULib
+export ULIB_ROOT=$IROOT/ULib
 export ULIB_DOCUMENT_ROOT=${ULIB_ROOT}/ULIB_DOCUMENT_ROOT
-export ULIB_BUILD_OUTPUT=${ULIB_ROOT}/ULIB_BUILD_OUTPUT.txt
-export ULIB_SERVER_OUTPUT=${ULIB_ROOT}/ULIB_SERVER_OUTPUT.txt

+ 31 - 15
ULib/install.sh

@@ -15,47 +15,63 @@
 #    . $FWROOT/ULib/install.sh (cwd=$FWROOT//installs)
 # --------------------------------------------------------------------------------------------------------
 
+# Chekc if ULib is already installed
+RETCODE=$(fw_exists ulib-${ULIB_VERSION}.installed)
+[ ! "$RETCODE" == 0 ] || { return 0; }
+
+# Create a run directory for ULIB
 if [ ! -d "$ULIB_ROOT" ]; then
   mkdir -p $ULIB_ROOT
 fi
 
+# Add a simple configuration file to it
 cd $ULIB_ROOT
+if [ ! -f "benchmark.cfg" ]; then
+  cat <<EOF >benchmark.cfg
+userver {
+ PORT 8080
+ PREFORK_CHILD 8
+ LISTEN_BACKLOG 8192
+ MAX_KEEP_ALIVE 8192
+ DOCUMENT_ROOT $ULIB_DOCUMENT_ROOT
+ PID_FILE ${ULIB_ROOT}/userver_tcp.pid
+}
+EOF
+fi
 
 # 1. Download ULib
-if [ ! -f "v${ULIB_VERSION}.tar.gz" ]; then
-	wget -nc --no-check-certificate --trust-server-names -O v${ULIB_VERSION}.tar.gz \
-        https://github.com/stefanocasazza/ULib/archive/v${ULIB_VERSION}.tar.gz 2>/dev/null
+cd $IROOT
+fw_get -O ULib-${ULIB_VERSION}.tar.gz https://github.com/stefanocasazza/ULib/archive/v${ULIB_VERSION}.tar.gz 
+fw_untar ULib-${ULIB_VERSION}.tar.gz
 
-	tar xf v${ULIB_VERSION}.tar.gz 2>/dev/null
-fi
+# 2. Compile application (userver_tcp)
 
 cd ULib-$ULIB_VERSION
 
-# 2. Compile application (userver_tcp)
-# ======================================================================================================
-# TO AVOID configure: error: newly created file is older than distributed files! Check your system clock
-# ======================================================================================================
+# AVOID "configure: error: newly created file is older than distributed files! Check your system clock"
 find . -exec touch {} \;
-# ======================================================================================================
 
-#           --enable-debug \
 LIBS="-lssl -lcrypto -lz" \
 ./configure --prefix=$ULIB_ROOT \
             --disable-static \
             --with-mysql \
             --without-ssl --without-pcre --without-expat \
             --without-libz --without-libuuid --without-magic \
-            --enable-static-orm-driver=mysql --enable-static-server-plugin=http >$ULIB_BUILD_OUTPUT 2>&1
-
-make -j1 install >>$ULIB_BUILD_OUTPUT 2>&1
+            --enable-static-orm-driver=mysql --enable-static-server-plugin=http
+#           --enable-debug \
+make install
 
 # 3. Compile usp pages for benchmark
 cd src/ulib/net/server/plugin/usp
-make -j1 db.la fortunes.la json.la plaintext.la queries.la updates.la >>$ULIB_BUILD_OUTPUT 2>&1
+make db.la fortunes.la json.la plaintext.la queries.la updates.la
 
+# Check that compilation worked
 if [ ! -e .libs/db.so ]; then
    exit 1
 fi
 
 mkdir -p $ULIB_DOCUMENT_ROOT
 cp .libs/db.so .libs/fortunes.so .libs/json.so .libs/plaintext.so .libs/queries.so .libs/updates.so $ULIB_DOCUMENT_ROOT
+
+cd $IROOT
+touch ulib-${ULIB_VERSION}.installed 

+ 10 - 161
ULib/setup.py

@@ -1,56 +1,3 @@
-# setup.py
-
-# THIS CALLING IS WORKING
-# ----------------------------------------------------------------------
-# toolset/run-tests.py --install server --test ULib --type all --verbose
-# ----------------------------------------------------------------------
-# ....
-# ULib: setup.py running - FWROOT is /home/tfb/FrameworkBenchmarks
-# ....
-# INFO:root:Running installation for ULib
-# INSTALL: 
-#    export TROOT=$FWROOT/ULib && 
-#    export IROOT=$FWROOT/installs && 
-#    . $FWROOT/toolset/setup/linux/bash_functions.sh && 
-#    . $FWROOT/ULib/install.sh (cwd=$FWROOT//installs)
-# ....
-# -----------------------------------------------------
-#   Running Test: ULib ...
-# -----------------------------------------------------
-# ULib: TROOT is EMPTY
-# ULib: setup.py START - IROOT is /home/tfb/FrameworkBenchmarks/installs/pertest/ULib - TROOT is /home/tfb/FrameworkBenchmarks/ULib
-# ULib: bash_profile.sh script START
-# ULib: trying to start server /home/tfb/FrameworkBenchmarks/installs/pertest/ULib/ULib/bin/userver_tcp -c /home/tfb/FrameworkBenchmarks/installs/pertest/ULib/ULib/benchmark.cfg
-# ULib: server STARTED
-# {'results': []}
-# ULib: TROOT is EMPTY
-# ULib: setup.py STOP - IROOT is /home/tfb/FrameworkBenchmarks/installs/pertest/ULib - TROOT is /home/tfb/FrameworkBenchmarks/ULib
-# ULib: bash_profile.sh script START
-# ----------------------------------------------------------------------
-
-# NOW THIS CALLING IS WORKING TOO BUT IT IS CORRECT TO CALL IT BEFORE INSTALLING...?
-# ----------------------------------------------------------------------------------
-# toolset/run-tests.py --test ULib --type all --verbose
-# ----------------------------------------------------------------------------------
-# ....
-# ULib: setup.py running - FWROOT is /home/tfb/FrameworkBenchmarks
-# ....
-# -----------------------------------------------------
-#   Running Test: ULib ...
-# -----------------------------------------------------
-# ULib: TROOT is EMPTY
-# ULib: setup.py START - IROOT is /home/tfb/FrameworkBenchmarks/installs/pertest/ULib - TROOT is /home/tfb/FrameworkBenchmarks/ULib
-# ULib: bash_profile.sh script START
-# ULib: NOT INSTALLED...
-# ULib: install.sh script START
-# ULib: trying to start server /home/tfb/FrameworkBenchmarks/installs/pertest/ULib/ULib/bin/userver_tcp -c /home/tfb/FrameworkBenchmarks/installs/pertest/ULib/ULib/benchmark.cfg
-# ULib: server STARTED
-# {'results': []}
-# ULib: TROOT is EMPTY
-# ULib: setup.py STOP - IROOT is /home/tfb/FrameworkBenchmarks/installs/pertest/ULib - TROOT is /home/tfb/FrameworkBenchmarks/ULib
-# ULib: bash_profile.sh script START
-# -----------------------------------------------------
-
 import os
 import sys
 import time
@@ -61,100 +8,14 @@ import multiprocessing
 
 #log = logging.getLogger('framework_test')
 
-fwroot = setup_util.get_fwroot()
-
-print(    "ULib: setup.py running - FWROOT is %s" % fwroot)
-#log.info("ULib: setup.py running - FWROOT is %s" % fwroot)
-
-# Queries the shell for the value of IROOT
-def get_iroot():
-  try:
-    # Use printf to avoid getting a newline
-    # Redirect to avoid stderr printing
-    iroot = subprocess.check_output('printf \"$IROOT\" 2>/dev/null', shell=True, executable='/bin/bash')
-    if iroot != "":
-      return iroot
-    print(       'ULib: IROOT is EMPTY')
-#   log.critical('ULib: IROOT is EMPTY')
-    return setup_util.get_fwroot() + "/installs"
-  except subprocess.CalledProcessError:
-    return "";
-
-# Queries the shell for the value of TROOT
-def get_troot():
-  try:
-    # Use printf to avoid getting a newline
-    # Redirect to avoid stderr printing
-    troot = subprocess.check_output('printf \"$TROOT\" 2>/dev/null', shell=True, executable='/bin/bash')
-    if troot != "":
-      return troot
-    print(       'ULib: TROOT is EMPTY')
-#   log.critical('ULib: TROOT is EMPTY')
-    return setup_util.get_fwroot() + "/ULib"
-  except subprocess.CalledProcessError:
-    return "";
-
-def getEnvironmentVar(name, iroot, troot):
-  try:
-    script = """
-export IROOT=%s
-. %s/bash_profile.sh 2>>/tmp/ULib_setup.txt
-printf $%s           2>>/tmp/ULib_setup.txt
-"""
-    value = subprocess.check_output(script % (iroot, troot, name), shell=True, executable='/bin/bash')
-    return value
-  except subprocess.CalledProcessError:
-    return "";
-
-def callScriptAndCheckForInstallation(name, iroot, troot):
-  try:
-    script = """
-export IROOT=%s
-export TROOT=%s
-. %s/%s.sh >>/tmp/ULib_setup.txt 2>&1
-if [ ! -x "${ULIB_ROOT}/bin/userver_tcp" ] || [ ! -e "${ULIB_DOCUMENT_ROOT}/db.so" ] || [ ! -f "${ULIB_ROOT}/benchmark.cfg" ]; then
-  exit 1
-fi
-"""
-    print(   "ULib: %s.sh script START" % name)
-#   log.info("ULib: %s.sh script START" % name)
-    return subprocess.call(script % (iroot, troot, troot, name), shell=True, executable='/bin/bash')
-  except subprocess.CalledProcessError:
-    return 1
 
-# --------------------------------------------------------------------------------------------------------
-# TROOT - Path of this test's directory
-# IROOT - Path of this test's install directory ($FWROOT/installs or $FWROOT/installs/pertest/<test-name>)
-# --------------------------------------------------------------------------------------------------------
-def checkEnvironment(iroot, troot):
-  try:
-    if callScriptAndCheckForInstallation('bash_profile', iroot, troot) != 0:
-      print(       'ULib: NOT INSTALLED...')
-#     log.critical('ULib: NOT INSTALLED...')
-      if callScriptAndCheckForInstallation('install', iroot, troot) != 0:
-        print(   "ULib: install.sh script FAILED")
-#       log.info("ULib: install.sh script FAILED")
-        return False
-    return True
-  except:
-    pass
-  return False
 
-##############
-# start(args)
-##############
 def start(args, logfile, errfile):
-  try:
-    iroot = get_iroot()
-    troot = get_troot()
-
-    print(   "ULib: setup.py START - IROOT is %s - TROOT is %s" % (iroot, troot))
-#   log.info("ULib: setup.py START - IROOT is %s - TROOT is %s" % (iroot, troot))
 
-    if not checkEnvironment(iroot, troot):
-      return 1
+  fwroot = args.fwroot
 
-    ulib_root = getEnvironmentVar('ULIB_ROOT', iroot, troot)
+  try:
+    ulib_root = subprocess.check_output('printf $ULIB_ROOT', shell=True, stderr=errfile)
 
     fcfg = ulib_root + "/benchmark.cfg"
 
@@ -168,22 +29,18 @@ def start(args, logfile, errfile):
     fprg = ulib_root + "/bin/userver_tcp"
 
     # 2. Start ULib Server (userver_tcp)
-    print(   "ULib: trying to start server " + fprg + " -c " + fcfg)
-#   log.info("ULib: trying to start server " + fprg + " -c " + fcfg)
+    logfile.write("ULib: trying to start server %s -c %s\n" % (fprg, fcfg))
 
     # sudo mysqlcheck -v -r -A -u benchmarkdbuser -p
     os.putenv("ORM_DRIVER","mysql")
     os.putenv("ORM_OPTION","host=" + args.database_host + " user=benchmarkdbuser password=benchmarkdbpass dbname=hello_world")
     os.putenv("UMEMPOOL", "1583,1507,-19,45,16458,523,-27,-14,27")
 
-    ulib_server_output = getEnvironmentVar('ULIB_SERVER_OUTPUT', iroot, troot)
-
     # Run in the background, but keep stdout/stderr for easy debugging
-    subprocess.Popen(                      fprg + " -c " + fcfg + " >" + ulib_server_output + " 2>&1", shell=True, stdout=logfile, stderr=errfile)
-  # subprocess.Popen("UTRACE=\"0 50M\" " + fprg + " -c " + fcfg + " >" + ulib_server_output + " 2>&1", shell=True, stdout=logfile, stderr=errfile)
+    subprocess.Popen( "%s -c %s" % (fprg, fcfg), shell=True, stdout=logfile, stderr=errfile)
+    # subprocess.Popen("UTRACE=\"0 50M\" " + fprg + " -c " + fcfg, shell=True, stdout=logfile, stderr=errfile)
 
-    print(   "ULib: server STARTED")
-#   log.info("ULib: server STARTED")
+    logfile.write("ULib: server STARTED\n")
     return 0
   except subprocess.CalledProcessError:
     return 1
@@ -193,19 +50,11 @@ def start(args, logfile, errfile):
 ##############
 def stop(logfile, errfile):
   try:
-    iroot = get_iroot()
-    troot = get_troot()
-
-    print(   "ULib: setup.py STOP - IROOT is %s - TROOT is %s" % (iroot, troot))
-#   log.info("ULib: setup.py STOP - IROOT is %s - TROOT is %s" % (iroot, troot))
-
-    if not checkEnvironment(iroot, troot):
-        return 1
+    logfile.write( "ULib: setup.py STOP\n")
 
-    ulib_root = getEnvironmentVar('ULIB_ROOT', iroot, troot)
 
     # Stop ULib Server (userver_tcp)
-    subprocess.check_call("kill -TERM $( cat " + ulib_root + "/userver_tcp.pid )", shell=True, stderr=errfile, stdout=logfile)
+    subprocess.check_call("kill -TERM $( cat $ULIB_ROOT/userver_tcp.pid )", shell=True, stderr=errfile, stdout=logfile)
     time.sleep(2);
     p = subprocess.Popen(['ps', 'aux'], stdout=subprocess.PIPE)
     out, err = p.communicate()
@@ -213,7 +62,7 @@ def stop(logfile, errfile):
        if 'userver_tcp' in line:
          pid = int(line.split(None, 2)[1])
          os.kill(pid, 9)
-    subprocess.call("rm -f " + ulib_root + "/userver_tcp.pid /tmp/ULib_setup.txt", shell=True, stderr=errfile, stdout=logfile)
+    subprocess.call("rm -f $ULIB_ROOT/userver_tcp.pid", shell=True, stderr=errfile, stdout=logfile)
     return 0
   except subprocess.CalledProcessError:
     return 1