setup_ruby.py 1.4 KB

1234567891011121314151617181920212223242526272829303132333435
  1. import subprocess
  2. import sys
  3. import re
  4. import os
  5. import setup_util
  6. import time
  7. def start(args, logfile, errfile):
  8. setup_util.replace_text("rails/config/database.yml", "host: .*", "host: " + args.database_host)
  9. try:
  10. subprocess.check_call("cp Gemfile-ruby Gemfile", shell=True, cwd="rails", stderr=errfile, stdout=logfile)
  11. subprocess.check_call("cp Gemfile-ruby.lock Gemfile.lock", shell=True, cwd="rails", stderr=errfile, stdout=logfile)
  12. subprocess.check_call("sudo /usr/local/nginx/sbin/nginx -c $TROOT/config/nginx.conf", shell=True, stderr=errfile, stdout=logfile)
  13. subprocess.Popen("rvm 2.1.2 do bundle exec unicorn_rails -E production -c $TROOT/config/unicorn.rb", shell=True, cwd="rails", stderr=errfile, stdout=logfile)
  14. return 0
  15. except subprocess.CalledProcessError:
  16. return 1
  17. def stop(logfile, errfile):
  18. subprocess.call("sudo /usr/local/nginx/sbin/nginx -c $TROOT/config/nginx.conf -s stop", shell=True, stderr=errfile, stdout=logfile)
  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, 15)
  26. subprocess.check_call("rm -f Gemfile", shell=True, cwd="rails")
  27. subprocess.check_call("rm -f Gemfile.lock", shell=True, cwd="rails")
  28. return 0
  29. except subprocess.CalledProcessError:
  30. return 1