Skip to content

Use with load balancers and containers

Most health checkers decide on the HTTP status: 200 is healthy, anything else is not. The health endpoint returns 503 for DOWN and OUT_OF_SERVICE, so every checker below works without parsing the JSON.

Pick the path by what the checker does when it fails:

The checker… Use
stops sending traffic to the instance /actuator/health/readiness
restarts or replaces the instance /actuator/health/liveness
alerts a human /actuator/health

Set the target group health check:

Setting Value
Protocol HTTP
Path /actuator/health/readiness
Success codes 200
Interval 10 seconds
Timeout 5 seconds
Unhealthy threshold 2

With Terraform:

resource "aws_lb_target_group" "app" {
# ...
health_check {
path = "/actuator/health/readiness"
matcher = "200"
interval = 10
timeout = 5
unhealthy_threshold = 2
}
}

The same settings apply to Google Cloud load balancers, Azure Application Gateway and most other load balancers.

Dockerfile
HEALTHCHECK --interval=30s --timeout=3s --start-period=10s --retries=3 \
CMD curl --fail --silent http://localhost:8080/actuator/health/liveness || exit 1

curl --fail exits with an error on HTTP 503. If the image has no curl, use PHP:

Dockerfile
HEALTHCHECK CMD php -r 'exit(@file_get_contents("http://localhost:8080/actuator/health/liveness") === false ? 1 : 0);'

Start a service only when the application is ready:

compose.yaml
services:
app:
build: .
healthcheck:
test: ["CMD", "curl", "--fail", "--silent", "http://localhost:8080/actuator/health/readiness"]
interval: 10s
timeout: 3s
retries: 5
worker:
build: .
command: php artisan queue:work
depends_on:
app:
condition: service_healthy

Point external monitors, such as Oh Dear, UptimeRobot or Pingdom, at /actuator/health. Configure them to alert on any status other than 200. To alert on one dependency only, give it a group and monitor the group path.

Laravel applications have a built-in /up health route. It returns 200 when the application boots and, by default, checks no dependency. You can keep both:

  • /up for the simplest liveness checks.
  • /actuator/health/readiness and /actuator/health when the check must see maintenance mode or dependencies.