setup.py 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. import subprocess
  2. import sys
  3. import setup_util
  4. import os
  5. from os.path import expanduser
  6. home = expanduser("~")
  7. def start(args):
  8. setup_util.replace_text("php/dborm.php", "@.*\/hello_world", "@" + args.database_host + "/hello_world")
  9. setup_util.replace_text("php/dbraw.php", "host=.*;", "host=" + args.database_host + ";")
  10. setup_util.replace_text("php/deploy/php", "\".*\/FrameworkBenchmarks", "\"" + home + "/FrameworkBenchmarks")
  11. setup_util.replace_text("php/deploy/php", "Directory .*\/FrameworkBenchmarks", "Directory " + home + "/FrameworkBenchmarks")
  12. try:
  13. #subprocess.check_call("sudo cp php/deploy/php /etc/apache2/sites-available/", shell=True)
  14. #subprocess.check_call("sudo a2ensite php", shell=True)
  15. #subprocess.check_call("sudo chown -R www-data:www-data php", shell=True)
  16. #subprocess.check_call("sudo /etc/init.d/apache2 start", shell=True)
  17. subprocess.check_call("sudo php-fpm --fpm-config config/php-fpm.conf", shell=True)
  18. subprocess.check_call("sudo /usr/local/nginx/sbin/nginx -c " + home + "FrameworkBenchmarks/php/deploy/nginx.conf", shell=True)
  19. return 0
  20. except subprocess.CalledProcessError:
  21. return 1
  22. def stop():
  23. try:
  24. subprocess.check_call("sudo /usr/local/nginx/sbin/nginx -s stop", shell=True)
  25. p = subprocess.Popen(['ps', 'aux'], stdout=subprocess.PIPE)
  26. out, err = p.communicate()
  27. for line in out.splitlines():
  28. if 'php-fpm' in line:
  29. try:
  30. pid = int(line.split(None, 2)[1])
  31. os.kill(pid, 9)
  32. except OSError:
  33. pass
  34. return 0
  35. except subprocess.CalledProcessError:
  36. return 1