setup.py 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. import subprocess
  2. import sys
  3. import setup_util
  4. import os
  5. from os.path import expanduser
  6. home = expanduser("~")
  7. def start(args, logfile, errfile):
  8. # compile the app
  9. setup_util.replace_text("nawak/nawak_app.nim", "host=.* port=5432", "host=" + args.database_host + " port=5432")
  10. subprocess.check_call("nimrod c -d:release --path:../installs/nawak/nawak nawak_app.nim",
  11. shell=True, cwd="nawak", stderr=errfile, stdout=logfile)
  12. # launch mongrel2
  13. subprocess.check_call("mkdir -p run logs tmp", shell=True, cwd="nawak/conf", stderr=errfile, stdout=logfile)
  14. subprocess.check_call("m2sh load -config mongrel2.conf", shell=True, cwd="nawak/conf", stderr=errfile, stdout=logfile)
  15. subprocess.check_call("sudo m2sh start -name test", shell=True, cwd="nawak/conf", stderr=errfile, stdout=logfile)
  16. for i in range(1, 43):
  17. # launch workers
  18. subprocess.Popen("./nawak_app " + str(i), shell=True, cwd="nawak", stderr=errfile, stdout=logfile)
  19. return 0
  20. def stop(logfile, errfile):
  21. subprocess.check_call("sudo m2sh stop -every", shell=True, cwd="nawak/conf", stderr=errfile, stdout=logfile)
  22. p = subprocess.Popen(['ps', 'aux'], stdout=subprocess.PIPE)
  23. out, err = p.communicate()
  24. for line in out.splitlines():
  25. if 'nawak_app' in line:
  26. try:
  27. pid = int(line.split(None, 2)[1])
  28. os.kill(pid, 9)
  29. except OSError:
  30. pass
  31. return 0