Skip to content

Commit

Permalink
Remove system specific commands.
Browse files Browse the repository at this point in the history
  • Loading branch information
shubhamJay committed Jul 31, 2019
1 parent fb4eb82 commit 98b19ef
Showing 1 changed file with 10 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,21 @@ import scala.util.Try

object Ports {

private[embedded_keycloak] def checkAvailability(port: Int, throwOnError: Boolean = false): Boolean = {
private[embedded_keycloak] def checkAvailability(
port: Int,
throwOnError: Boolean = false
): Boolean = {
val free = isFree(port = port)
if (!free && throwOnError) throw new RuntimeException(s"port $port is not available.")
if (!free && throwOnError)
throw new RuntimeException(s"port $port is not available.")
free
}

def stop(port: Long): Unit = {
proc("lsof", "-n", s"-i4TCP:$port") |
proc("grep", "LISTEN") |
proc("awk", "{print $2}") |
proc("xargs", "kill", "-9")
proc("sh", "-c", "lsof", "-n", s"-i4TCP:$port") |
proc("sh", "-c", "grep", "LISTEN") |
proc("sh", "-c", "awk", "{print $2}") |
proc("sh", "-c", "xargs", "kill", "-9")
}

def isFree(host: String = "localhost", port: Int): Boolean =
Expand Down

0 comments on commit 98b19ef

Please sign in to comment.