What is the equivalent to 'play stop' for

2019-02-06 06:08发布

问题:

What is the equivalent of play stop for Play 2.1?

If I did play start, how do I cleanly terminate the process?

回答1:

As stated in the doc:

When you run the start command, Play forks a new JVM and runs the default Netty HTTP server. The standard output stream is redirected to the Play console, so you can monitor its status.

The server’s process id is displayed at bootstrap and written to the RUNNING_PID file. To kill a running Play server, it is enough to send a SIGTERM to the process to properly shutdown the application.

If you type Ctrl+D, the Play console will quit, but the created server process will continue running in background. The forked JVM’s standard output stream is then closed, and logging can be read from the logs/application.log file.

So I think that you have to use play run instead of play start. Then you'll be able to use Ctrl+D to stop play.



回答2:

On Windows I'm using the following script to kill the currently running play server

@echo off
if exist RUNNING_PID (
  setlocal EnableDelayedExpansion
  set /p PLAY_PID=<RUNNING_PID
  echo killing pid !PLAY_PID!
  taskkill /F /PID !PLAY_PID!
  del RUNNING_PID
  endlocal
) 


回答3:

You can run this script:

kill $(cat /your-play-project-path/target/universal/stage/RUNNING_PID)


回答4:

If you ran your app using the play start command, issuing the play stop command from the app directory does work and will stop the running application server.

I verified this works in Play 2.1.1.



回答5:

Simply press Ctrl + D in the console window.



回答6:

To achieve this, you could modify the build.sbt file as described here.

TaskKey[Unit]("stop") := {
  val pidFile = target.value / "universal" / "stage" / "RUNNING_PID"
  if (!pidFile.exists) throw new Exception("App not started!")
  val pid = IO.read(pidFile)
  s"kill $pid".!
  println(s"Stopped application with process ID $pid")
}

However, this only applies to *nix systems.



回答7:

You can call <your_server_url>/@kill , e.g. : http://localhost:9022/app3/@kill