setup.py 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. import subprocess
  2. import sys
  3. import setup_util
  4. import os
  5. from zipfile import ZipFile
  6. def start(args):
  7. setup_util.replace_text("play-activate-mysql/conf/application.conf", "jdbc:mysql:\/\/.*:3306", "jdbc:mysql://" + args.database_host + ":3306")
  8. subprocess.check_call("play clean dist", shell=True, cwd="play-activate-mysql")
  9. if os.name == 'nt':
  10. ZipFile("./play-activate-mysql/target/universal/play-activate-mysql-1.0-SNAPSHOT.zip").extractall("./play-activate-mysql/target/universal")
  11. with open("./play-activate-mysql/target/universal/play-activate-mysql-1.0-SNAPSHOT/bin/play-activate-mysql.bat", "w+") as f:
  12. f.write("java %1 -cp \"./lib/*;\" play.core.server.NettyServer .")
  13. subprocess.Popen("play-activate-mysql.bat", shell=True, cwd="play-activate-mysql/target/universal/play-activate-mysql-1.0-SNAPSHOT/bin")
  14. else:
  15. subprocess.check_call("unzip play-activate-mysql-1.0-SNAPSHOT.zip", shell=True, cwd="play-activate-mysql/target/universal")
  16. subprocess.check_call("chmod +x play-activate-mysql", shell=True, cwd="play-activate-mysql/target/universal/play-activate-mysql-1.0-SNAPSHOT/bin")
  17. subprocess.Popen("./play-activate-mysql", shell=True, cwd="play-activate-mysql/target/universal/play-activate-mysql-1.0-SNAPSHOT/bin")
  18. return 0
  19. def stop():
  20. if os.name == 'nt':
  21. with open("./play-activate-mysql/target/universal/play-activate-mysql-1.0-SNAPSHOT/RUNNING_PID") as f:
  22. pid = int(f.read())
  23. os.kill(pid, 9)
  24. else:
  25. kill_running_process()
  26. try:
  27. os.remove("play-activate-mysql/target/universal/play-activate-mysql-1.0-SNAPSHOT/RUNNING_PID")
  28. except OSError:
  29. pass
  30. return 0
  31. def kill_running_process():
  32. try:
  33. with open("./play-activate-mysql/target/universal/play-activate-mysql-1.0-SNAPSHOT/RUNNING_PID") as f:
  34. pid = int(f.read())
  35. os.kill(pid,9)
  36. except:
  37. pass