setup.py 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. import subprocess
  2. import sys
  3. import os
  4. import setup_util
  5. from os.path import expanduser
  6. def start(args, logfile, errfile):
  7. fwroot = args.fwroot
  8. setup_util.replace_text("cakephp/app/Config/database.php", "'host' => '.*',", "'host' => '" + args.database_host + "',")
  9. setup_util.replace_text("cakephp/deploy/cake", "\".*\/FrameworkBenchmarks/cakephp", "\"%s" % args.troot)
  10. setup_util.replace_text("cakephp/deploy/cake", "Directory .*\/FrameworkBenchmarks/cakephp", "Directory %s" % args.troot)
  11. setup_util.replace_text("cakephp/deploy/nginx.conf", "root .*\/FrameworkBenchmarks/cakephp", "root %s" % args.troot)
  12. try:
  13. if os.name == 'nt':
  14. setup_util.replace_text("cakephp/app/Config/core.php", "'Apc'", "'Wincache'")
  15. subprocess.check_call('icacls "C:\\FrameworkBenchmarks\\cakephp" /grant "IIS_IUSRS:(OI)(CI)F"', shell=True, stderr=errfile, stdout=logfile)
  16. subprocess.check_call('appcmd add site /name:PHP /bindings:http/*:8080: /physicalPath:"C:\\FrameworkBenchmarks\\cakephp\\app\\webroot"', shell=True, stderr=errfile, stdout=logfile)
  17. return 0
  18. #subprocess.check_call("sudo cp cake/deploy/cake /etc/apache2/sites-available/", shell=True)
  19. #subprocess.check_call("sudo a2ensite cake", shell=True)
  20. subprocess.check_call("sudo chown -R www-data:www-data cakephp", shell=True, stderr=errfile, stdout=logfile)
  21. # Sudo needed to switch to correct user
  22. # This is a bit tricky as sudo normally resets the PATH for security
  23. # To work around that in this one case, we use the full
  24. # path to the php-fpm binary we setup in bash_profile.sh
  25. subprocess.check_call("sudo $PHP_FPM --fpm-config $FWROOT/config/php-fpm.conf -g $TROOT/deploy/php-fpm.pid", shell=True, stderr=errfile, stdout=logfile)
  26. subprocess.check_call("sudo /usr/local/nginx/sbin/nginx -c $TROOT/deploy/nginx.conf", shell=True, stderr=errfile, stdout=logfile)
  27. return 0
  28. except subprocess.CalledProcessError:
  29. return 1
  30. def stop(logfile, errfile):
  31. try:
  32. if os.name == 'nt':
  33. subprocess.call('appcmd delete site PHP', shell=True, stderr=errfile, stdout=logfile)
  34. return 0
  35. subprocess.call("sudo /usr/local/nginx/sbin/nginx -s stop", shell=True, stderr=errfile, stdout=logfile)
  36. subprocess.call("sudo kill -QUIT $( cat $TROOT/deploy/php-fpm.pid )", shell=True, stderr=errfile, stdout=logfile)
  37. #subprocess.check_call("sudo a2dissite cake", shell=True)
  38. #subprocess.check_call("sudo /etc/init.d/apache2 stop", shell=True)
  39. subprocess.check_call("sudo chown -R $USER:$USER cakephp", shell=True, stderr=errfile, stdout=logfile)
  40. return 0
  41. except subprocess.CalledProcessError:
  42. return 1