Add EmbeddedServerPortFileWriter

Add a EmbeddedServerPortFileWriter which can be used to write server
port information to a file.

Fixes gh-1275
Closes gh-1491
This commit is contained in:
Phillip Webb
2014-10-08 23:03:35 -07:00
parent 77ccd9a80b
commit 6a423d7ad1
5 changed files with 313 additions and 27 deletions

View File

@@ -856,30 +856,38 @@ if needed.
[[production-ready-process-monitoring]]
== Process monitoring
In Spring Boot Actuator you can find `ApplicationPidFileWriter` which creates file
containing application PID (by default in application directory and file name is
`application.pid`). It's not activated by default, but you can do it in two simple
ways described below.
In Spring Boot Actuator you can find a couple of classes to create files that are useful
for process monitoring:
* `ApplicationPidFileWriter` creates a file containing the application PID (by default in
the application directory with the file name `application.pid`).
* `EmbeddedServerPortFileWriter` creates a file (or files) containing the ports of the
embedded server (by default in the application directory with the file name
`application.port`).
These writers are not activated by default, but you can enable them in one of the ways
described below.
[[production-ready-process-monitoring-configuration]]
=== Extend configuration
In `META-INF/spring.factories` file you have to activate the listener:
In `META-INF/spring.factories` file you have to activate the listener(s):
[indent=0]
----
org.springframework.context.ApplicationListener=\
org.springframework.boot.actuate.system.ApplicationPidFileWriter
org.springframework.boot.actuate.system.ApplicationPidFileWriter,
org.springframework.boot.actuate.system.EmbeddedServerPortFileWriter
----
[[production-ready-process-monitoring-programmatically]]
=== Programmatically
You can also activate this listener by invoking `SpringApplication.addListeners(...)`
method and passing `ApplicationPidFileWriter` object. You can also customize file name
and path through constructor.
You can also activate a listener by invoking the `SpringApplication.addListeners(...)`
method and passing the appropriate `Writer` object. This method also allows you to
customize file name and path via the `Writer` constructor.