setup.py 1.7 KB

1234567891011121314151617181920212223242526272829
  1. import subprocess
  2. import sys
  3. import setup_util
  4. from os.path import expanduser
  5. import os
  6. import getpass
  7. home = expanduser("~")
  8. def start(args, logfile, errfile):
  9. setup_util.replace_text("plack/app.psgi", "localhost", ""+ args.database_host +"")
  10. setup_util.replace_text("plack/nginx.conf", "USR", getpass.getuser())
  11. setup_util.replace_text("plack/nginx.conf", "server unix:.*\/FrameworkBenchmarks", "server unix:" + home + "/FrameworkBenchmarks")
  12. try:
  13. subprocess.check_call("curl -L http://cpanmin.us | perl - App::cpanminus", shell=True, cwd="plack", stderr=errfile, stdout=logfile)
  14. subprocess.check_call("cpanm --notest --no-man-pages --installdeps "+home+"/FrameworkBenchmarks/plack", shell=True, cwd="plack", stderr=errfile, stdout=logfile)
  15. subprocess.Popen("start_server --backlog=16384 --pid-file="+home+"/FrameworkBenchmarks/plack/app.pid --path="+home+"/FrameworkBenchmarks/plack/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+128) + " -a "+home+"/FrameworkBenchmarks/plack/app.psgi", shell=True, cwd="plack", stderr=errfile, stdout=logfile)
  16. subprocess.check_call("sudo /usr/local/nginx/sbin/nginx -c " + home + "/FrameworkBenchmarks/plack/nginx.conf", shell=True, stderr=errfile, stdout=logfile)
  17. return 0
  18. except subprocess.CalledProcessError:
  19. return 1
  20. def stop(logfile, errfile):
  21. try:
  22. subprocess.call('kill -TERM $(cat '+home+"/FrameworkBenchmarks/plack/app.pid)", shell=True, cwd="plack", stderr=errfile, stdout=logfile)
  23. subprocess.call("sudo /usr/local/nginx/sbin/nginx -s stop", shell=True)
  24. return 0
  25. except subprocess.CalledProcessError:
  26. return 1