Advertisement
Guest User

Untitled

a guest
Dec 20th, 2014
145
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.40 KB | None | 0 0
  1. import java.io.{ File, FileWriter }
  2. import scala.sys.process.Process
  3.  
  4. object Main {
  5.  
  6. val MEX_HOME = "/home/itang/mex/workspace/mex-front-side"
  7.  
  8. val JAR_FILE = MEX_HOME + "/target/tdb-0.1.0-SNAPSHOT.jar"
  9.  
  10. val TARGET_DIR = "/tmp/mex_scala"
  11.  
  12. val TARGET_LIB_DIR = TARGET_DIR + "/lib"
  13.  
  14. implicit class sw(s: String) {
  15. def exec() = Process(s.split("\\s").toList, new File(MEX_HOME)).!!
  16. def writeTo(file: File) = {
  17. val writer = new FileWriter(file)
  18. writer.write(s)
  19. writer.close()
  20. }
  21. }
  22.  
  23. def main(args: Array[String]): Unit = {
  24. prepare()
  25. taskJar()
  26. taskCopyLibs()
  27. taskRunShell()
  28.  
  29. System.exit(0)
  30. }
  31.  
  32. def prepare(): Unit = {
  33. s"rm -rf $TARGET_DIR".exec
  34. s"mkdir -p $TARGET_LIB_DIR".exec
  35. }
  36.  
  37. def taskJar(): Unit = {
  38. s"lein jar".exec
  39. s"cp $JAR_FILE $TARGET_LIB_DIR".exec
  40. }
  41.  
  42. def taskCopyLibs(): Unit = {
  43. val cps: String = s"lein with-profile uberjar classpath".exec
  44. for (jar ← cps.split(":").filter(_.endsWith(".jar"))) {
  45. s"cp $jar $TARGET_LIB_DIR".exec
  46. }
  47. }
  48.  
  49. def taskRunShell() = {
  50. val cps = new File(TARGET_LIB_DIR).listFiles().map(_.getAbsolutePath).toList.mkString(":")
  51. val content = s"""#!/bin/bash
  52.  
  53. export RUN_MODE=prod
  54. export DATA_DIR=./data
  55.  
  56. CLASSPATH=${cps}
  57.  
  58. nohup java -Xms1g -Xmx2g -Xss1M -XX:MaxPermSize=392m -cp $$CLASSPATH clojure.main -m app.core &
  59.  
  60. """
  61.  
  62. content writeTo new File(TARGET_DIR, "run.sh")
  63. }
  64. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement