16
votes

What is the equivalent of play stop for Play 2.1?

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

7

7 Answers

12
votes

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.

18
votes

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
) 
10
votes

You can run this script:

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

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.

0
votes

Simply press Ctrl + D in the console window.

0
votes

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.

0
votes

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