diff --git a/framework/src/play/src/main/scala/play/core/server/NettyServer.scala b/framework/src/play/src/main/scala/play/core/server/NettyServer.scala index 478acd88843..e0b87512512 100644 --- a/framework/src/play/src/main/scala/play/core/server/NettyServer.scala +++ b/framework/src/play/src/main/scala/play/core/server/NettyServer.scala @@ -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 {