Navigation Menu

Skip to content

Commit

Permalink
[fixes playframework#342] allow more flexibility when it comes to PID…
Browse files Browse the repository at this point in the history
… file handling
  • Loading branch information
ph2734 committed Jun 4, 2012
1 parent bc0f0b4 commit 17c750b
Showing 1 changed file with 13 additions and 13 deletions.
Expand Up @@ -147,26 +147,26 @@ object NettyServer {
* @param applicationPath path to application
*/
def createServer(applicationPath: File): Option[NettyServer] = {

// Manage RUNNING_PID file
java.lang.management.ManagementFactory.getRuntimeMXBean.getName.split('@').headOption.map { pid =>
val pidPath = Option(System.getProperty("pidfile.path")).getOrElse(applicationPath.getAbsolutePath())
val pidFile = new File(pidPath, "RUNNING_PID")

if (pidFile.exists) {
println("This application is already running (Or delete the RUNNING_PID file).")
System.exit(-1)
}
val pidFile = Option(System.getProperty("pidfile.path")).map(new File(_)).getOrElse(new File(applicationPath.getAbsolutePath, "RUNNING_PID"))

// The Logger is not initialized yet, we print the Process ID on STDOUT
println("Play server process ID is " + pid)

new FileOutputStream(pidFile).write(pid.getBytes)
Runtime.getRuntime.addShutdownHook(new Thread {
override def run {
pidFile.delete()
if (pidFile.getAbsolutePath != "/dev/null") {
if (pidFile.exists) {
println("This application is already running (Or delete "+ pidFile.getAbsolutePath +" file).")
System.exit(-1)
}
})

new FileOutputStream(pidFile).write(pid.getBytes)
Runtime.getRuntime.addShutdownHook(new Thread {
override def run {
pidFile.delete()
}
})
}
}

try {
Expand Down

0 comments on commit 17c750b

Please sign in to comment.