setup.py 2.7 KB

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