setup.py 1.2 KB

123456789101112131415161718192021222324252627282930
  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("kelp/app.pl", "localhost", args.database_host)
  9. setup_util.replace_text("kelp/nginx.conf", "USR", getpass.getuser())
  10. setup_util.replace_text("kelp/nginx.conf", "server unix:.*\/FrameworkBenchmarks/kelp", "server unix:" + args.troot)
  11. try:
  12. subprocess.Popen("plackup -E deployment -s Starman --workers=" + str(args.max_threads) + " -l $TROOT/frameworks-benchmark.sock -a $TROOT/app.pl", shell=True, cwd="kelp", 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.call("sudo /usr/local/nginx/sbin/nginx -s stop", shell=True, stderr=errfile, stdout=logfile)
  20. p = subprocess.Popen(['ps', 'aux'], stdout=subprocess.PIPE)
  21. out, err = p.communicate()
  22. for line in out.splitlines():
  23. if 'starman' in line:
  24. pid = int(line.split(None, 2)[1])
  25. os.kill(pid, 15)
  26. return 0
  27. except subprocess.CalledProcessError:
  28. return 1