setup.py 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. import subprocess
  2. import sys
  3. import setup_util
  4. from os.path import expanduser
  5. import os
  6. import getpass
  7. def start(args, logfile, errfile):
  8. setup_util.replace_text("plack/app.psgi", "localhost", args.database_host)
  9. setup_util.replace_text("plack/nginx.conf", "USR", getpass.getuser())
  10. setup_util.replace_text("plack/nginx.conf", "server unix:.*\/FrameworkBenchmarks/plack", "server unix:" + args.troot)
  11. try:
  12. subprocess.Popen("start_server --backlog=16384 --pid-file=$TROOT/app.pid --path=$TROOT/app.sock -- plackup -E production -s Starlet --max-keepalive-reqs 1000 --max-reqs-per-child 50000 --min-reqs-per-child 40000 --max-workers=" + str(args.max_threads+4) + " -a $TROOT/app.psgi", shell=True, cwd="plack", stderr=errfile, stdout=logfile)
  13. subprocess.check_call("sudo /usr/local/nginx/sbin/nginx -c $TROOT/nginx.conf", shell=True,stderr=errfile, stdout=logfile)
  14. return 0
  15. except subprocess.CalledProcessError:
  16. return 1
  17. def stop(logfile, errfile):
  18. try:
  19. subprocess.Popen("kill -TERM $(ps --ppid `cat app.pid` -o pid --no-header)", shell=True, cwd="plack", stderr=errfile, stdout=logfile)
  20. # TE - There was an issue on the EC2 machines where this, for reasons unknown,
  21. # was not sufficient in cleanly ending plack. In fact, the above would not
  22. # successfully kill the starter process which would result in this 'stop' call
  23. # to report success but leave port 8080 bound to a plackup instance. We tried
  24. # adding a 'nuke' approach which detects the test's port still being bound
  25. # after calling stop and then directly kills those pids a few times to try and
  26. # cleanly release any/all ports (over 6000).
  27. # Why this only happens on EC2 is just a guess, but somehow the server seems
  28. # overwhelmed by the sheer volume of requests from the client and gets into
  29. # a deadlock state. Calling "kill -15 [pid]" against the server process does
  30. # nothing; so we needed a general way to kill all the processes that were
  31. # spawned by the original process. For plack, this was as simple as the next
  32. # subprocess.Popen call (killall -s 9 plackup), but to do this generally is
  33. # a bit more difficult.
  34. # TE - In general, no test should ever be forced to use the KILL sigterm;
  35. # TERM should be sufficient. However, in this case it seems that the plack
  36. # server gets into a deadlock state and will not respond to a TERM sigterm.
  37. subprocess.Popen("killall -s 9 plackup")
  38. return 0
  39. except subprocess.CalledProcessError:
  40. return 1