setup.py 993 B

123456789101112131415161718192021222324252627282930313233343536
  1. import subprocess
  2. import sys
  3. import json
  4. from os.path import expanduser
  5. import os
  6. import getpass
  7. home = expanduser("~")
  8. def start(args, logfile, errfile):
  9. conf = {
  10. 'database_host' : args.database_host,
  11. 'workers' : args.max_threads,
  12. }
  13. with open('mojolicious/app.conf', 'w') as f:
  14. f.write(json.dumps(conf))
  15. try:
  16. # os.environ["MOJO_MODE"] = "production"
  17. subprocess.Popen("hypnotoad ./app.pl", shell=True, cwd="mojolicious", stderr=errfile, stdout=logfile)
  18. return 0
  19. except subprocess.CalledProcessError:
  20. return 1
  21. def stop(logfile, errfile):
  22. try:
  23. subprocess.call("hypnotoad -s ./app.pl", shell=True, cwd="mojolicious", stderr=errfile, stdout=logfile)
  24. p = subprocess.Popen(['ps', 'aux'], stdout=subprocess.PIPE)
  25. out, err = p.communicate()
  26. for line in out.splitlines():
  27. if 'hypnotoad' in line:
  28. pid = int(line.split(None, 2)[1])
  29. os.kill(pid, 15)
  30. return 0
  31. except subprocess.CalledProcessError:
  32. return 1