setup_jruby.py 1.4 KB

12345678910111213141516171819202122232425262728293031
  1. import subprocess
  2. import sys
  3. import os
  4. import setup_util
  5. def start(args, logfile, errfile):
  6. setup_util.replace_text("rails/config/database-jruby.yml", "host: .*", "host: " + args.database_host)
  7. try:
  8. subprocess.check_call("rvm jruby-1.7.8 do bundle install --gemfile=Gemfile-jruby", shell=True, cwd="rails", stderr=errfile, stdout=logfile)
  9. subprocess.check_call("cp Gemfile-jruby Gemfile", shell=True, cwd="rails", stderr=errfile, stdout=logfile)
  10. subprocess.check_call("cp Gemfile-jruby.lock Gemfile.lock", shell=True, cwd="rails", stderr=errfile, stdout=logfile)
  11. subprocess.check_call("cp config/database-jruby.yml config/database.yml", shell=True, cwd="rails", stderr=errfile, stdout=logfile)
  12. subprocess.Popen("rvm jruby-1.7.8 do bundle exec torqbox -b 0.0.0.0 -E production", shell=True, cwd="rails", stderr=errfile, stdout=logfile)
  13. return 0
  14. except subprocess.CalledProcessError:
  15. return 1
  16. def stop(logfile, errfile):
  17. try:
  18. p = subprocess.Popen(['ps', 'aux'], stdout=subprocess.PIPE)
  19. out, err = p.communicate()
  20. for line in out.splitlines():
  21. if 'torqbox' in line:
  22. pid = int(line.split(None, 2)[1])
  23. os.kill(pid, 15)
  24. subprocess.check_call("rm Gemfile", shell=True, cwd="rails", stderr=errfile, stdout=logfile)
  25. subprocess.check_call("rm Gemfile.lock", shell=True, cwd="rails", stderr=errfile, stdout=logfile)
  26. return 0
  27. except subprocess.CalledProcessError:
  28. return 1