sablierapp/sablier 是一个托管在 GitHub 上的开源项目,主要使用 Go 编写,采用 GNU Affero General Public License v3.0 许可证,目前获得 3.2k 个 Star、108 次 Fork。
仓库全名
sablierapp/sablier
README 摘要
Free and open-source software that starts workloads on demand and stops them after a period of inactivity. It integrates with reverse proxy plugins (Traefik, Caddy, Nginx, Envoy, etc.) to intercept incoming requests, wake up sleeping workloads, and display a waiting page until they're ready. Whether you're running on a resource-constrained device like a Raspberry Pi, managing a QA environment used only once a week,…
Start your containers on demand, shut them down automatically when there's no activity. Docker, Docker Swarm Mode, Podman, Kubernetes, Proxmox LXC, SystemD, AWS ECS and Nomad compatible.
Free and open-source software that starts workloads on demand and stops them after a period of inactivity.
It integrates with reverse proxy plugins (Traefik, Caddy, Nginx, Envoy, etc.) to intercept incoming requests, wake up sleeping workloads, and display a waiting page until they’re ready.
Whether you’re running on a resource-constrained device like a Raspberry Pi, managing a QA environment used only once a week, or reducing cloud costs by scaling idle workloads to zero — Sablier is built for you.
Key features:
On-demand start/stop for Docker, Kubernetes, Podman, Proxmox LXC, systemd, Nomad and AWS ECS workloads
Customizable waiting UI with themes while workloads warm up
Here we run sablierapp/mimic, a configurable web-server for testing purposes.
Caution 注意
You should always use a healthcheck with your application that needs to be scaled to zero.
Without a healtheck, Sablier cannot distinguish a started container from a container ready to receive incoming requests.
2. Stop the Container
Stop the container to simulate a scaled-down state:
docker stop mimic
Tip 提示
Sablier can automatically stop containers at startup using the --provider.auto-stop-on-startup flag, which will stop all containers with sablier.enable=true labels.
3. Start Sablier
Start the Sablier server with the Docker provider:
Call the Sablier API to start a session for the demo group:
curl -v http://localhost:10000/api/strategies/blocking\?group\=demo\&session_duration\=20s
* Request completely sent off
< HTTP/1.1 200 OK
< X-Sablier-Session-Status: ready
Sablier will start the mimic container automatically for 20 seconds…
Tip 提示
Check out the Usage with Reverse Proxies section to integrate Sablier with Traefik, Caddy, Nginx, and more.
5. Verify the Container is Running
docker ps | grep mimic
6. Wait for Session Expiration
After the session duration (20 seconds in this example), Sablier will automatically stop the container.
# Wait 20 seconds, then check
docker ps -a | grep mimic
Configuration sources are evaluated in the order listed above with later methods overriding earlier ones.
If no value is provided for a given option, a default value is used.
Configuration File
At startup, Sablier searches for a configuration file named sablier.yml (or sablier.yaml) in:
/etc/sablier/
$XDG_CONFIG_HOME/
$HOME/.config/
.(the working directory)
You can override this using the configFile argument.
sablier --configFile=path/to/myconfigfile.yml
provider:
# Provider to use to manage containers (docker, swarm, kubernetes, podman, proxmox_lxc, systemd, nomad, ecs)
name: docker
# Reject requests for containers/services that don't have the Sablier enable label
reject-unlabeled-requests: false
# Verify that the Sablier enable label is present when an instance expires
verify-enabled-on-expiration: false
docker:
# Strategy to use when stopping containers (stop or pause)
strategy: stop
server:
# The server port to use
port: 10000
# The base path for the API
base-path: /
metrics:
# Enable Prometheus metrics endpoint
enabled: true
storage:
# File path to save the state (default stateless)
file:
sessions:
# The default session duration (default 5m)
default-duration: 5m
# The expiration checking interval.
# Higher duration gives less stress on CPU.
# If you only use sessions of 1h, setting this to 5m is a good trade-off.
expiration-interval: 20s
logging:
level: info
strategy:
dynamic:
# Custom themes folder, will load all .html files recursively.
# A missing folder is not an error, only the built-in themes are served then.
custom-themes-path: /etc/sablier/themes
# Show instances details by default in waiting UI
show-details-by-default: true
# Default theme used for dynamic strategy (default "hacker-terminal")
default-theme: hacker-terminal
# Default refresh frequency in the HTML page for dynamic strategy
default-refresh-frequency: 5s
blocking:
# Default timeout used for blocking strategy (default 1m)
default-timeout: 1m
webhooks:
endpoints:
# Notify an uptime-monitoring service every time an instance starts or stops.
# - url: https://uptime.example.com/api/push/xxxxxxxx
# headers:
# Authorization: "Bearer <token>"
# events:
# - started
# - stopped
tracing:
# Set enabled: true to export OpenTelemetry traces.
enabled: false
# exporterType selects the trace backend: "otlphttp" (default) or "stdout".
exporterType: otlphttp
# endpoint is the OTLP collector URL. Without a path, traces are sent to /v1/traces;
# a path is used as is.
# For Jaeger: http://jaeger:4318
# For Grafana Tempo: http://tempo:4318
# For VictoriaTraces: http://victoriatraces:10428/insert/opentelemetry/v1/traces
endpoint: http://localhost:4318
# serviceName is the logical name that appears in the tracing backend.
serviceName: sablier
# samplingRate controls the fraction of requests traced (0.0 – 1.0).
samplingRate: 1.0
Environment Variables
Environment variables follow the same structure as the configuration file and are prefixed with SABLIER_. For example:
By default, Sablier stops (or pauses) workloads when a session expires and restarts them on the next request. Scale mode is an alternative: instead of stopping a container, Sablier throttles its CPU, memory, and (on Docker) block I/O to a minimal idle allocation, then restores full resources the moment a new session arrives.
Because the container never stops, there is no cold-start latency — ideal for resource-constrained environments like a Raspberry Pi where you want to reclaim most of the hardware while keeping response times acceptable.
Scale mode is controlled entirely through labels:
labels:
- "sablier.enable=true"
- "sablier.group=myapp"
# Idle state: keep running but throttle resources
- "sablier.idle.replicas=1"
- "sablier.idle.cpu=0.1"
- "sablier.idle.memory=64m"
# Active state: full resources when a session is requested
- "sablier.active.replicas=1"
- "sablier.active.cpu=2.0"
- "sablier.active.memory=512m"
Label
Description
sablier.idle.replicas
Replica count while idle. Set to 0 to stop (default behaviour), 1+ to keep running.
sablier.idle.cpu
CPU limit while idle (e.g. 0.1 for 10% of one core). Requires idle.replicas >= 1.
sablier.idle.memory
Memory limit while idle (e.g. 64m). Requires idle.replicas >= 1.
Docker only: Block I/O throttling is supported on the Docker provider. Per-device limits (blkio-*-device, blkio-device-*) require a Docker daemon with API version ≥ 1.55 (moby/moby#52650); Sablier logs a warning on older daemons. See the configuration reference for the full list.
On a machine where several heavy services share a non-shareable resource (GPU VRAM, RAM), running two at once can OOM. Anti-affinity lets an instance back off automatically while another group is in use:
labels:
- "sablier.enable=true"
- "sablier.anti-affinity=streaming" # yield whenever the "streaming" group is active
When any session for the streaming group is active, every instance that declared an anti-affinity against it is forced idle (stopped, or throttled to its idle profile in scale mode) and restored once the group is no longer active. Multiple groups can be listed comma-separated.
Sablier can POST a normalized JSON notification to one or more HTTP endpoints whenever a managed instance starts or stops. Because Sablier sits in front of every supported provider, webhooks act as a unified, provider-agnostic event stream — your receiver always gets the same payload structure regardless of the underlying runtime.
Common uses:
Push heartbeats to an uptime monitor such as Uptime Kuma
Trigger CI/CD pipelines or automation on instance lifecycle events
Sablier exposes a Prometheus-compatible /metrics endpoint. Enable it in your configuration:
server:
metrics:
enabled: true
Tracing
Sablier supports distributed tracing via OpenTelemetry. When enabled, every incoming HTTP request and every call to the underlying container provider is captured as a span and exported to an OTLP-compatible backend such as Jaeger or Grafana Tempo. Trace context is propagated using the W3C TraceContext format, so if your reverse proxy injects a traceparent header, Sablier will join the existing trace.
Sablier adds ~1.5–2 ms of latency per request at steady state (session cache hot, container already running), sustaining ~5,000–5,750 req/s on a single core. Cold starts depend entirely on container startup time; once the container is ready, subsequent requests return to warm latency immediately.
Sablier is an API server that manages workload lifecycle. To automatically wake up workloads when users access your services, you can integrate Sablier with reverse proxy plugins.
These plugins intercept incoming requests, call the Sablier API to start sleeping workloads, and display a waiting page until they’re ready.
Apache APISIX
Sablier integrates with Apache APISIX through a Proxy-WASM plugin, enabling dynamic scaling for your services.
Quick Start:
Install the Sablier Proxy-WASM plugin
Configure APISIX routes with Sablier plugin settings
评论