setup_ruby.py 1.2 KB

123456789101112131415161718192021222324252627282930
  1. import subprocess
  2. import sys
  3. import re
  4. import os
  5. def start(args):
  6. try:
  7. subprocess.check_call("rvm ruby-2.0.0-p0 do bundle install --gemfile=Gemfile-ruby", shell=True, cwd="sinatra")
  8. subprocess.check_call("cp Gemfile-ruby Gemfile", shell=True, cwd="sinatra")
  9. subprocess.check_call("cp Gemfile-ruby.lock Gemfile.lock", shell=True, cwd="sinatra")
  10. subprocess.Popen("rvm ruby-2.0.0-p0 do bundle exec unicorn -E production -c config/unicorn.rb", shell=True, cwd="sinatra")
  11. return 0
  12. except subprocess.CalledProcessError:
  13. return 1
  14. def stop():
  15. try:
  16. p = subprocess.Popen(['ps', 'aux'], stdout=subprocess.PIPE)
  17. out, err = p.communicate()
  18. for line in out.splitlines():
  19. if 'unicorn' in line and 'master' in line:
  20. pid = int(line.split(None, 2)[1])
  21. os.kill(pid, 9)
  22. # subprocess.check_call("rvm ruby-2.0.0-p0 do bundle exec passenger stop --pid-file=$HOME/FrameworkBenchmarks/sinatra/sinatra.pid", shell=True, cwd='sinatra')
  23. subprocess.check_call("rm Gemfile", shell=True, cwd="sinatra")
  24. subprocess.check_call("rm Gemfile.lock", shell=True, cwd="sinatra")
  25. return 0
  26. except subprocess.CalledProcessError:
  27. return 1