setup.py 790 B

123456789101112131415161718192021222324252627
  1. import subprocess
  2. import sys
  3. import setup_util
  4. import os
  5. def start(args):
  6. setup_util.replace_text("nodejs/hello.js", "mongodb:\/\/.*\/hello_world", "mongodb://" + args.database_host + "/hello_world")
  7. setup_util.replace_text("nodejs/hello.js", "host: '.*',", "host: '" + args.database_host + "',")
  8. try:
  9. subprocess.check_call("npm install", shell=True, cwd="nodejs")
  10. subprocess.Popen("node hello.js", shell=True, cwd="nodejs")
  11. return 0
  12. except subprocess.CalledProcessError:
  13. return 1
  14. def stop():
  15. p = subprocess.Popen(['ps', 'aux'], stdout=subprocess.PIPE)
  16. out, err = p.communicate()
  17. for line in out.splitlines():
  18. if 'hello.js' in line:
  19. pid = int(line.split(None, 2)[1])
  20. try:
  21. os.kill(pid, 9)
  22. except OSError:
  23. pass
  24. return 0