setup.py 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. import os
  2. import sys
  3. import time
  4. #import logging
  5. import setup_util
  6. import subprocess
  7. import multiprocessing
  8. #log = logging.getLogger('framework_test')
  9. def start(args, logfile, errfile):
  10. fwroot = args.fwroot
  11. try:
  12. ulib_root = subprocess.check_output('printf $ULIB_ROOT', shell=True, stderr=errfile)
  13. fcfg = ulib_root + "/benchmark.cfg"
  14. # 1. Change ULib Server configuration
  15. # I don't understand if the two approach are different...
  16. #threads = str(args.max_threads)
  17. PROCS = str(multiprocessing.cpu_count())
  18. setup_util.replace_text(fcfg, "PREFORK_CHILD .*", "PREFORK_CHILD " + PROCS)
  19. fprg = ulib_root + "/bin/userver_tcp"
  20. # 2. Start ULib Server (userver_tcp)
  21. logfile.write("ULib: trying to start server %s -c %s\n" % (fprg, fcfg))
  22. # sudo mysqlcheck -v -r -A -u benchmarkdbuser -p
  23. os.putenv("ORM_DRIVER","mysql")
  24. os.putenv("ORM_OPTION","host=" + args.database_host + " user=benchmarkdbuser password=benchmarkdbpass dbname=hello_world")
  25. os.putenv("UMEMPOOL", "1583,1507,-19,45,16458,523,-27,-14,27")
  26. # Run in the background, but keep stdout/stderr for easy debugging
  27. subprocess.Popen( "%s -c %s" % (fprg, fcfg), shell=True, stdout=logfile, stderr=errfile)
  28. # subprocess.Popen("UTRACE=\"0 50M\" " + fprg + " -c " + fcfg, shell=True, stdout=logfile, stderr=errfile)
  29. logfile.write("ULib: server STARTED\n")
  30. return 0
  31. except subprocess.CalledProcessError:
  32. return 1
  33. ##############
  34. # stop()
  35. ##############
  36. def stop(logfile, errfile):
  37. try:
  38. logfile.write( "ULib: setup.py STOP\n")
  39. # Stop ULib Server (userver_tcp)
  40. subprocess.check_call("kill -TERM $( cat $ULIB_ROOT/userver_tcp.pid )", shell=True, stderr=errfile, stdout=logfile)
  41. time.sleep(2);
  42. p = subprocess.Popen(['ps', 'aux'], stdout=subprocess.PIPE)
  43. out, err = p.communicate()
  44. for line in out.splitlines():
  45. if 'userver_tcp' in line:
  46. pid = int(line.split(None, 2)[1])
  47. os.kill(pid, 9)
  48. subprocess.call("rm -f $ULIB_ROOT/userver_tcp.pid", shell=True, stderr=errfile, stdout=logfile)
  49. return 0
  50. except subprocess.CalledProcessError:
  51. return 1