Deploy and run
Sleep, schedules and instant wake
Let apps stop when nobody uses them or on a timetable, so you don't pay for idle time, and wake them in an instant.
An app that's asleep isn't running, so you don't pay for it. CLI can put apps to sleep three ways, and you can combine them:
- When nobody's using it. After 15 minutes, 30 minutes, an hour or 4 hours without visitors. The next visitor wakes it.
- On a schedule. For example, nights and weekends for a staging app: "sleep from 22:00 to 07:00, Monday to Friday, New York time". It wakes up by itself at 07:00. You choose whether a visitor can wake it during that time, or sees a page saying when it's back.
- Instant wake. Normally a waking app takes a few seconds, and the first visitor sees a "Starting…" page. With instant wake, CLI keeps the app ready while it sleeps, so the first visitor gets the real page straight away.
How to do it: open an app and go to Settings.
- Scaling, sleep and builds has the idle setting.
- Sleep schedule has the timetable: press Set a schedule.
- Instant wake has a single switch.
"Make my staging app sleep at night and on weekends, Toronto time."
What instant wake costs: where CLI's server supports it, the app's memory is saved to disk while it sleeps, which costs nothing. Otherwise it's frozen in memory: you pay for its memory only, with no CPU, which for a 256 MB app is about $7 a month if it slept all month. The panel shows the figure for your app. If cost matters more than the first visitor's wait, leave it off.
Idle sleep
PATCH /v1/services/:id {"sleepAfterMinutes": 30}5 to 1440 minutes, or null to stay on. Traffic is measured from what the app receives (CLI's own health checks don't count). POST /v1/services/:id/wake wakes it now. In cli.json: "deploy": {"sleepAfterMinutes": 30}.
Sleep schedules
PUT /v1/services/:id/sleep-schedule
{"schedule": {"tz": "America/Toronto", "from": "22:00", "to": "07:00", "days": [1, 2, 3, 4, 5], "wakeOnRequest": true}}| Field | Meaning |
|---|---|
tz | an IANA time zone; unknown ones are refused |
from, to | 24-hour HH:MM; they must differ |
days | the days a window starts on, 0 = Sunday … 6 = Saturday. A window that crosses midnight runs into the next morning |
wakeOnRequest | default true. false: visitors get a 503 page (or {"asleep": true, "wakesAt": "07:00 (America/Toronto)"} for JSON clients) until the window ends |
{"schedule": null} turns it off, and wakes the app if the schedule had put it to sleep. GET returns {schedule, description, asleepNow, inWindow}, with description like 22:00–07:00 Mon–Fri (America/Toronto).
The leader checks every minute: it sleeps apps entering their window and wakes the ones it put to sleep when the window ends (apps asleep for being idle are left alone). If a visitor wakes an app during its window, it goes back to sleep 15 minutes after the last request. Schedule sleeps and wakes appear on the app's What happened tab (see /docs/what-happened). Apps only; not previews.
Instant wake
PUT /v1/services/:id/instant-wake {"enabled": true}
GET /v1/services/:id/instant-wakeGET returns {enabled, asleepAs, lastWakeMs}, where asleepAs is stopped, paused or checkpoint while asleep and null while awake.
How it sleeps:
| Mode | When | Cost asleep | Wake |
|---|---|---|---|
checkpoint | the worker has CRIU and Docker's experimental checkpoints, and the operator set CLI_DOCKER_CHECKPOINTS=1 | nothing (memory saved to disk, container stopped) | well under a second |
paused | otherwise | memory at the usual rate, no CPU | milliseconds |
stopped | instant wake off | nothing | a few seconds |
A checkpoint that won't restore (after a kernel upgrade, say) falls back to a normal start; a paused app whose container was stopped meanwhile is started normally. When an instant wake finishes before the wake page would show, a GET or HEAD visitor gets a 307 back to the same URL, so they land on the app itself. Static sites don't need it: nothing runs for them anyway.