setup.py 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  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. setup_util.replace_text("nawak/model_postgre.nim", "host=.* port=5432",
  9. "host=" + args.database_host + " port=5432")
  10. # compile the app
  11. subprocess.check_call(
  12. "nimrod c --threads:on -d:release -d:postgre_model --path:../installs/nawak/nawak -o:nawak_postgre app.nim",
  13. shell=True, cwd="nawak", stderr=errfile, stdout=logfile)
  14. # launch mongrel2
  15. subprocess.check_call("mkdir -p run logs tmp", shell=True, cwd="nawak/conf", stderr=errfile, stdout=logfile)
  16. subprocess.check_call("sudo m2sh load -config mongrel2.conf", shell=True, cwd="nawak/conf", stderr=errfile, stdout=logfile)
  17. subprocess.check_call("sudo m2sh start -name test", shell=True, cwd="nawak/conf", stderr=errfile, stdout=logfile)
  18. # launch workers
  19. subprocess.Popen("./nawak_postgre", shell=True, cwd="nawak", stderr=errfile, stdout=logfile)
  20. return 0
  21. def stop(logfile, errfile):
  22. ret = 0
  23. try:
  24. subprocess.check_call("sudo m2sh stop -every", shell=True, cwd="nawak/conf", stderr=errfile, stdout=logfile)
  25. except:
  26. ret = 1
  27. p = subprocess.Popen(['ps', 'aux'], stdout=subprocess.PIPE)
  28. out, err = p.communicate()
  29. for line in out.splitlines():
  30. if 'nawak_postgre' in line:
  31. try:
  32. pid = int(line.split(None, 2)[1])
  33. os.kill(pid, 15)
  34. except OSError:
  35. ret = 1
  36. return ret