Skip to content

Instantly share code, notes, and snippets.

@pboos
Created November 8, 2012 13:14
Show Gist options
  • Save pboos/4038755 to your computer and use it in GitHub Desktop.
Save pboos/4038755 to your computer and use it in GitHub Desktop.
Lift Tutorial 2: Nice Server with Jetty and MongoDB
#!/usr/bin/env scala
!#
import java.io._
import scala.runtime.RichChar
import scala.io.Source
import scala.util.matching.Regex
import scala.collection.immutable.Stream
// SETTINGS
val FILE_NAME_ON_SERVER = "1.war"
val SCP_SERVER_NAME = "ec2.my_server.ch"
val SCP_SERVER_USER = "ec2-user"
val SCP_SERVER_ID_LOCATION = "/Users/patrickboos85/.ssh/my_server.id"
val SCP_SERVER_FOLDER = "/home/ec2-user/jetty/webapps"
println("### PACKAGING as .war (sbt package)")
def p = Runtime.getRuntime().exec("sbt package")
val WarFileExp = """.*Packaging \.(.*\.war) \.\.\..*""".r
var warLocation : String = ""
for (
line <- Source.fromInputStream(p.getInputStream()).getLines
) {
println(line)
if ((line contains "Packaging") && (line contains ".war")) {
val WarFileExp(warFile) = line
warLocation = System.getProperty("user.dir") + warFile
}
}
if (warLocation.length() > 0) {
val warFile = new File(warLocation)
println("### RENAMING TO " + FILE_NAME_ON_SERVER)
val renamedWarFile = new File(warFile.getParent + "/" + FILE_NAME_ON_SERVER)
warFile.renameTo(renamedWarFile)
println("### UPLOADING (this will take quite some time)")
val scpCommand = "scp -i " + SCP_SERVER_ID_LOCATION + " " + renamedWarFile.getAbsolutePath + " " + SCP_SERVER_USER + "@" + SCP_SERVER_NAME + ":" + SCP_SERVER_FOLDER
def p = Runtime.getRuntime().exec(scpCommand)
Source.fromInputStream(p.getInputStream()).foreach(print(_))
Source.fromInputStream(p.getErrorStream()).foreach(print(_))
println("### DONE")
} else {
println("### .war file was not created. See output. Maybe deployed already?")
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment