@groovy.transform.CompileStatic class RunningApplicationProcess extends java.lang.Object
Locates and stops the Grails application started by the CLI run-app command.
run-app launches an application as a forked Gradle bootRun JVM. The
GrailsGradlePlugin configures that bootRun task to tell the application to write
its own process id to a project local PID file (via Spring Boot's
ApplicationPidFileWriter). Because the contract is a file on disk - and not in-memory
state - stop-app can terminate the application even when it was forked into a separate
process or when grails stop-app is run from a different CLI invocation than the one that
started it.
Stopping is performed with java.lang.ProcessHandle#destroy(), which requests a graceful
shutdown (a SIGTERM on Unix-like systems, allowing the JVM shutdown hooks and
Spring's orderly shutdown to run). On platforms where the operating system has no
graceful equivalent (notably Windows) termination is best effort.
| Modifiers | Name | Description |
|---|---|---|
static enum |
RunningApplicationProcess.StopResult |
The result of a stop(File, long) request. |
| Type | Name and description |
|---|---|
static java.lang.String |
PID_FILE_NAMEThe name of the PID file written, relative to the project build directory. |
static java.lang.String |
STOP_MARKER_NAMEThe name of the marker file, relative to the project build directory, that stop-app
writes to signal a deliberate shutdown. |
| Type Params | Return Type | Name and description |
|---|---|---|
|
static void |
clearStopRequest(java.io.File buildDir)Removes any pending stop-app shutdown marker for the project. |
|
static boolean |
isRunning(java.io.File pidFile)
|
|
static boolean |
isStopRequested(java.io.File buildDir)
|
|
static java.util.Optional<java.lang.ProcessHandle> |
liveProcess(java.io.File pidFile)Resolves the live application process described by the PID file, applying a guard against recycled process ids. |
|
static java.io.File |
pidFile(java.io.File buildDir)
|
|
static java.lang.Long |
readPid(java.io.File pidFile)Reads the process id recorded in the given PID file. |
|
static void |
requestStop(java.io.File buildDir)Records that a deliberate stop-app shutdown is in progress, so a foreground
run-app blocked on the bootRun build can distinguish an intentional stop
from a startup failure when its process is terminated. |
|
static RunningApplicationProcess.StopResult |
stop(java.io.File pidFile, long timeoutMillis)Stops the application recorded in the PID file and removes the file once the process is gone. |
|
static java.io.File |
stopMarker(java.io.File buildDir)
|
| Methods inherited from class | Name |
|---|---|
class java.lang.Object |
java.lang.Object#equals(java.lang.Object), java.lang.Object#getClass(), java.lang.Object#hashCode(), java.lang.Object#notify(), java.lang.Object#notifyAll(), java.lang.Object#toString(), java.lang.Object#wait(), java.lang.Object#wait(long), java.lang.Object#wait(long, int) |
The name of the PID file written, relative to the project build directory.
The name of the marker file, relative to the project build directory, that stop-app
writes to signal a deliberate shutdown.
This marker is purely a message-classification hint and has nothing to do with how the
application is shut down (that is always a graceful ProcessHandle.destroy()). It exists
only for a foreground, blocking grails run-app: because stop-app terminates the
forked application JVM rather than the Gradle process, the bootRun build returns a
non-zero child exit, which would otherwise be reported as a startup failure. The marker lets
that run-app report a clean stop instead. It is an empty file - only its presence
matters - and it is cleared at the start of the next run-app so it can never mask a
genuine startup failure.
Removes any pending stop-app shutdown marker for the project.
buildDir - the project build directory
pidFile - the PID filetrue if an application started by run-app is currently running
buildDir - the project build directorytrue if a stop-app shutdown has been requested for the projectResolves the live application process described by the PID file, applying a guard against recycled process ids.
pidFile - the PID file
buildDir - the project build directoryrun-appReads the process id recorded in the given PID file.
pidFile - the PID filenull if the file is missing, empty, malformed or
not a positive process id Records that a deliberate stop-app shutdown is in progress, so a foreground
run-app blocked on the bootRun build can distinguish an intentional stop
from a startup failure when its process is terminated.
The marker is an empty file; only its presence is meaningful (see isStopRequested).
buildDir - the project build directoryStops the application recorded in the PID file and removes the file once the process is gone.
pidFile - the PID filetimeoutMillis - the maximum time to wait for the process to terminate
buildDir - the project build directorystop-app shutdown is in progress