Stop, pause, hibernate
Three ways to put a box away, and what each does with its memory.
A box that is not in use can be put away three ways. They differ in what happens to its memory:
| files | memory | host RAM | comes back | |
|---|---|---|---|---|
kvbox stop | kept | gone | freed | start: a fresh boot, a few seconds |
kvbox pause | kept | kept in RAM | still used | resume: instant, processes and connections intact |
kvbox hibernate | kept | written to disk | freed | wake: well under a second, processes intact |
pause is for a short break: nothing is lost and nothing has to be written, but the box still holds its RAM on the host.
hibernate is a snapshot the box takes of itself: its memory goes into a file next to its disk (only the pages it used, a few hundred MB for a fresh box) and the VM process ends. The box survives a server restart or a host reboot in that state, and wake brings it back exactly where it was, clock included.
stop is pulling the plug: processes are gone, files stay. stop on a hibernated box throws that saved memory away.
connect and exec resume or wake a sleeping box on their own, the way connect starts a stopped one. kvbox ls shows which state each box is in.
Hibernate on its own
A box can hibernate by itself once it has had no network traffic, in or out, for a while:
kvbox new --auto-hibernate 30m # at creation
kvbox vm set <box> --auto-hibernate 4h
kvbox vm set <box> --auto-hibernate offThe host looks once a minute, so the timeout is in minutes, hours or days. Any traffic counts, an SSH session or a download alike, and starts the timeout over. A session opened with kvbox connect or kvbox exec counts even while nothing happens in it; with your own ssh, add -o ServerAliveInterval=60 for the same. Work that only uses the CPU with nobody connected (a build left running in the background) looks idle, so give such a box a timeout longer than the job, or none. A box you paused stays paused: only running boxes hibernate on their own. Off is the default. kvbox connect and kvbox exec wake the box as usual, and so does a visit to its HTTPS address (https://<sub>.kvbox.app), so a site can hibernate when nobody uses it.
A box can decide for itself what idle means: give it an idle check, a script inside the box that exits 0 when it is idle, and the host asks that once a minute instead of watching the traffic:
kvbox vm set <box> --idle-check /home/kvbox/idle.sh --auto-hibernate 15m
kvbox vm set <box> --idle-check off # back to network trafficThe script runs as root and has 10 seconds to answer; an error counts as busy. Some images come with one: a GitHub runner box is idle while no job runs, and hibernates after 10 minutes of that by default. The check runs through kvbox-agent, so a box made before base image v0.12.0 needs kvbox vm update first. A box takes its image's check when it is made; an update never adds one, so an older box gets it with kvbox vm set --idle-check.
Wake it from outside
A wake hook is a URL that wakes the box when something calls it: a GitHub webhook, a cron job, another service. It needs kvbox.sh.
kvbox vm hook create ci # prints the URL and its secret, shown only this once
kvbox vm hook ls ci
kvbox vm hook rm ci <id>Sign each call with the secret, either as a bearer:
curl -X POST -H "Authorization: Bearer <secret>" https://api.kvbox.sh/hooks/wh_…or the way GitHub signs its webhooks (X-Hub-Signature-256), so a GitHub webhook works as is: in the repository's Settings → Webhooks, set the Payload URL to the hook's URL, the content type to application/json, the secret to the hook's secret, and pick the Workflow jobs event. A self-hosted runner on a hibernated box then wakes when a job is queued: GitHub keeps the job waiting until the runner comes back online.
A call wakes a hibernated box and resumes a paused one. For a running box it counts as activity: the box stays awake for its full auto-hibernate time from that call, so work that is queued but has not reached the box yet (a CI job for a runner) does not find it asleep. A stopped box stays stopped: stopping is on purpose. A hook acts on its box at most once a minute, and not at all while your account (or the box's org) is out of credit. GitHub's test ping wakes nothing. Lost the secret? Remove the hook and make a new one.
Hibernating again is up to the box's own auto-hibernate. A GitHub runner box hibernates 10 minutes after its last job.