setup_ruby.py 1.5 KB

123456789101112131415161718192021222324252627282930313233343536
  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):
  9. setup_util.replace_text("sinatra/hello_world.rb", ":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="sinatra")
  12. subprocess.check_call("cp Gemfile-ruby Gemfile", shell=True, cwd="sinatra")
  13. subprocess.check_call("cp Gemfile-ruby.lock Gemfile.lock", shell=True, cwd="sinatra")
  14. subprocess.check_call("sudo /usr/local/nginx/sbin/nginx -c " + home + "/FrameworkBenchmarks/sinatra/config/nginx.conf", shell=True)
  15. subprocess.Popen("rvm ruby-2.0.0-p0 do bundle exec unicorn_rails -E production -c config/unicorn.rb", shell=True, cwd="sinatra")
  16. return 0
  17. except subprocess.CalledProcessError:
  18. return 1
  19. def stop():
  20. subprocess.call("sudo /usr/local/nginx/sbin/nginx -s stop", shell=True)
  21. try:
  22. p = subprocess.Popen(['ps', 'aux'], stdout=subprocess.PIPE)
  23. out, err = p.communicate()
  24. for line in out.splitlines():
  25. if 'unicorn' in line and 'master' in line:
  26. pid = int(line.split(None, 2)[1])
  27. os.kill(pid, 9)
  28. # 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')
  29. subprocess.check_call("rm Gemfile", shell=True, cwd="sinatra")
  30. subprocess.check_call("rm Gemfile.lock", shell=True, cwd="sinatra")
  31. return 0
  32. except subprocess.CalledProcessError:
  33. return 1