execute nohup command with playframework get Bad file descriptor error

linux, nohup, playframework, playframework-2.2, scala

Solution

The error happens because standard input get redirected from `/dev/null` by `nohup` - you get the same error if you do `play start < /dev/null`. The sbt process starts the actual server in a separate process, the sets itself up to display logs and wait for you to type Ctrl-D or Ctrl-C. It uses JLine to wait for user input, which attempts to attach to the standard input as a terminal. `/dev/null` can't be used in this way, so it dies complaining of a bad file descriptor. However, the background server process continues running.

If you want to start Play non-interactively, you need to use the stage task. See Using the stage task in the Play documentation.

Problem

I use playframework2.2 and sbt 0.13.1, I can run the sbt and start the server on command line sbt start it works ok. but when I run: nohup sbt start It run a while and then stop with log error: ``` (Starting server. Type Ctrl+D to exit logs, the server will remain in background) java.io.IOException: Bad file descriptor at java.io.FileInputStream.read0(Native Method) at java.io.FileInputStream.read(FileInputStream.java:210) at jline.internal.NonBlockingInputStream.read(NonBlockingInputStream.java:248) at jline.internal.InputStreamReader.read(InputStreamReader.java:261) at jline.internal.InputStreamReader.read(InputStreamReader.java:198) at jline.console.ConsoleReader.readCharacter(ConsoleReader.java:2038) at play.PlayConsoleInteractionMode$$anonfun$waitForKey$1.play$PlayConsoleInteractionMode$$anonfun$$waitEOF$1(PlayInteractionMode.scala:36) at play.PlayConsoleInteractionMode$$anonfun$waitForKey$1$$anonfun$apply$1.apply$mcV$sp(PlayInteractionMode.scala:45) at play.PlayConsoleInteractionMode$$anonfun$doWithoutEcho$1.apply(PlayInteractionMode.scala:52) at play.PlayConsoleInteractionMode$$anonfun$doWithoutEcho$1.apply(PlayInteractionMode.scala:49) at play.PlayConsoleInteractionMode$.withConsoleReader(PlayInteractionMode.scala:31) at play.PlayConsoleInteractionMode$.doWithoutEcho(PlayInteractionMode.scala:49) at play.PlayConsoleInteractionMode$$anonfun$waitForKey$1.apply(PlayInteractionMode.scala:45) at play.PlayConsoleInteractionMode$$anonfun$waitForKey$1.apply(PlayInteractionMode.scala:34) at play.PlayConsoleInteractionMode$.withConsoleReader(PlayInteractionMode.scala:31) at play.PlayConsoleInteractionMode$.waitForKey(PlayInteractionMode.scala:34) at play.PlayConsoleInteractionMode$.waitForCancel(PlayInteractionMode.scala:55) at play.PlayRun$$anonfun$24$$anonfun$apply$9.apply(PlayRun.scala:373) at play.PlayRun$$anonfun$24$$anonfun$apply$9.apply(PlayRun.scala:352) at scala.util.Either$RightProjection.map(Either.scala:536) at play.PlayRun$$anonfun$24.apply(PlayRun.scala:352) at play.PlayRun$$anonfun$24.apply(PlayRun.scala:334) at sbt.Command$$anonfun$sbt$Command$$apply1$1$$anonfun$apply$6.apply(Command.scala:72) at sbt.Command$.process(Command.scala:95) at sbt.MainLoop$$anonfun$1$$anonfun$apply$1.apply(MainLoop.scala:100) at sbt.MainLoop$$anonfun$1$$anonfun$apply$1.apply(MainLoop.scala:100) at sbt.State$$anon$1.process(State.scala:179) at sbt.MainLoop$$anonfun$1.apply(MainLoop.scala:100) at sbt.MainLoop$$anonfun$1.apply(MainLoop.scala:100) at sbt.ErrorHandling$.wideConvert(ErrorHandling.scala:18) at sbt.MainLoop$.next(MainLoop.scala:100) at sbt.MainLoop$.run(MainLoop.scala:93) at sbt.MainLoop$$anonfun$runWithNewLog$1.apply(MainLoop.scala:71) at sbt.MainLoop$$anonfun$runWithNewLog$1.apply(MainLoop.scala:66) at sbt.Using.apply(Using.scala:25) at sbt.MainLoop$.runWithNewLog(MainLoop.scala:66) at sbt.MainLoop$.runAndClearLast(MainLoop.scala:49) at sbt.MainLoop$.runLoggedLoop(MainLoop.scala:33) at sbt.MainLoop$.runLogged(MainLoop.scala:25) at sbt.StandardMain$.runManaged(Main.scala:57) at sbt.xMain.run(Main.scala:29) at xsbt.boot.Launch$$anonfun$run$1.apply(Launch.scala:57) at xsbt.boot.Launch$.withContextLoader(Launch.scala:77) at xsbt.boot.Launch$.run(Launch.scala:57) at xsbt.boot.Launch$$anonfun$explicit$1.apply(Launch.scala:45) at xsbt.boot.Launch$.launch(Launch.scala:65) at xsbt.boot.Launch$.apply(Launch.scala:16) at xsbt.boot.Boot$.runImpl(Boot.scala:32) at xsbt.boot.Boot$.main(Boot.scala:21) at xsbt.boot.Boot.main(Boot.scala) error[0m] [0mjava.io.IOException: Bad file descriptor[0m error[0m] [0mUse 'last' for the full log.[0m ``` Any one know which file is Bad file descriptor. And How to solve this problem.

Original source