Service Startup Dependencies
lzcapp provides two fields related to service dependencies to handle timing issues during application startup
- Simplified
depends_onfield - Health check mechanism automatically injected based on
application.routesfield
depends_on
In most cases, depends_on only needs to be used under the services.$service_name field, type is []string Each entry fills in a $service_name, the current service will wait for all services in depends_on to have container status as healthy when starting
The service.$service_name.health_check field will affect the service entering healthy state. This field has the same semantics as docker-compose's healthCheck, but only supports the following 4 fields
type HealthCheckConfig struct {
Test []string `yaml:"test"`
TestUrl string `yaml:"test_url"`
StartPeriod time.Duration `yaml:"start_period"`
Disable bool `yaml:"disable"`
}type HealthCheckConfig struct {
Test []string `yaml:"test"`
TestUrl string `yaml:"test_url"`
StartPeriod time.Duration `yaml:"start_period"`
Disable bool `yaml:"disable"`
}health_check example:
services:
wordpress:
image: bitnami/wordpress:5.8.2
health_check:
test:
- CMD-SHELL
- "curl -f http://localhost:80/ || exit 1"
# test_url: http://localhost:80 # URL for health check, health check fails if status code is greater than 500
start_period: 190s
disable: falseservices:
wordpress:
image: bitnami/wordpress:5.8.2
health_check:
test:
- CMD-SHELL
- "curl -f http://localhost:80/ || exit 1"
# test_url: http://localhost:80 # URL for health check, health check fails if status code is greater than 500
start_period: 190s
disable: falseWARNING
- The corresponding field in lzcapp is
health_checkinstead ofhealthCheck- Even if
health_checkis not filled in the service, it will still be affected by the corresponding field in the docker image
Automatically Injected Health Checks
lzcapp mainly provides services externally through application.routes, so the system will automatically perform intelligent detection based on the upstream state in routes. Therefore, in most cases, there is no need to manually handle dependencies. The specific rules are as follows:
- Detect and wait for all service containers to enter running state
- Detect and wait for the corresponding service in
application.health_check.test_urlto return 200 status (if this configuration exists) - Detect and wait for all upstreams to be ready, then the special service
applicationenters healthy state The specific method is to scan all routes rules and extract thehttp://$hostname:$portpart. exec type will be automatically converted tohttp://127.0.0.1:$portUse TCP dial$hostname:$port, if dial succeeds, it indicates that this upstream is ready - Wait for all other services to enter healthy state, the "Application starting" page switches to actual service content
WARNING
- If
$hostnameis a public IP/domain, step 3 will ignore this upstream service to avoid LCMD being unable to start this application without internet- When dialing
$hostname:$port, HTTP method is not used, because some upstreams are in 404 or other strange states when normal Therefore, the automatically injected detection logic only ensures TCP level is normal- Due to the existence of automatic injection, never fill in the special service_name
appinservices.$service_name.depends_on- If you encounter dependency-related issues during development, you can set
application.health_check.disable=trueto disable automatically injected health checks, but it is strongly recommended to enable it when officially releasing the application