setup_ruby.py 1.5 KB

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