setup_jruby.py 1.2 KB

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