setup_ruby.py 1.4 KB

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