setup_ruby.py 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. import subprocess
  2. import sys
  3. import re
  4. import os
  5. import setup_util
  6. from os.path import expanduser
  7. home = expanduser("~")
  8. def start(args, logfile, errfile):
  9. setup_util.replace_text("rails/config/database-ruby.yml", "host: .*", "host: " + args.database_host)
  10. try:
  11. subprocess.check_call("rvm ruby-2.0.0-p0 do bundle install --gemfile=Gemfile-ruby", shell=True, cwd="rails", stderr=errfile, stdout=logfile)
  12. subprocess.check_call("cp Gemfile-ruby Gemfile", shell=True, cwd="rails", stderr=errfile, stdout=logfile)
  13. subprocess.check_call("cp Gemfile-ruby.lock Gemfile.lock", shell=True, cwd="rails", stderr=errfile, stdout=logfile)
  14. subprocess.check_call("cp config/database-ruby.yml config/database.yml", shell=True, cwd="rails", stderr=errfile, stdout=logfile)
  15. subprocess.check_call("sudo /usr/local/nginx/sbin/nginx -c " + home + "/FrameworkBenchmarks/rails/config/nginx.conf", shell=True, stderr=errfile, stdout=logfile)
  16. subprocess.Popen("rvm ruby-2.0.0-p0 do bundle exec unicorn_rails -E production -c config/unicorn.rb", shell=True, cwd="rails", stderr=errfile, stdout=logfile)
  17. return 0
  18. except subprocess.CalledProcessError:
  19. return 1
  20. def stop(logfile, errfile):
  21. subprocess.call("sudo /usr/local/nginx/sbin/nginx -s stop", shell=True, stderr=errfile, stdout=logfile)
  22. try:
  23. p = subprocess.Popen(['ps', 'aux'], stdout=subprocess.PIPE)
  24. out, err = p.communicate()
  25. for line in out.splitlines():
  26. if 'unicorn' in line and 'master' in line:
  27. pid = int(line.split(None, 2)[1])
  28. os.kill(pid, 15)
  29. # subprocess.check_call("rvm ruby-2.0.0-p0 do bundle exec passenger stop --pid-file=$HOME/FrameworkBenchmarks/rack/rack.pid", shell=True, cwd='rack')
  30. subprocess.check_call("rm Gemfile", shell=True, cwd="rails")
  31. subprocess.check_call("rm Gemfile.lock", shell=True, cwd="rails")
  32. return 0
  33. except subprocess.CalledProcessError:
  34. return 1