setup.py 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  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. ret = 0
  22. try:
  23. subprocess.check_call("sudo m2sh stop -every", shell=True, cwd="nawak/conf", stderr=errfile, stdout=logfile)
  24. except:
  25. ret = 1
  26. p = subprocess.Popen(['ps', 'aux'], stdout=subprocess.PIPE)
  27. out, err = p.communicate()
  28. for line in out.splitlines():
  29. if 'nawak_app' in line:
  30. try:
  31. pid = int(line.split(None, 2)[1])
  32. os.kill(pid, 15)
  33. except OSError:
  34. ret = 1
  35. return ret