Skip to content
Barely

Docs / Use

Sleep and hibernate

Docs · Sleep and hibernate

Projects sleep

A project is a compose project, or a container started without compose. A compose project sleeps and wakes whole, never in part.

When nothing has used a project for sleep_after (15 minutes by default), it goes to sleep. Its containers are paused and their memory goes back to macOS. In the app, Activity and the menu bar show which projects are asleep. In the terminal, barely status lists them, and docker ps shows their containers as Paused.

Each of these counts as use. Each is a sleep_signals entry, and all are on by default:

Signal What counts
traffic Network traffic in or out of the project: from your Mac, another project or the internet. Traffic between its own containers doesn't count
logs Anything a container writes to its output
files A file changed on your Mac in one of its bind mounts
cpu More than 5% of one core, averaged over a minute
cron A cron daemon running in it (crond, cron, supercronic, anacron or fcron), or a timer set to fire, such as a systemd timer

Waking

A sleeping project wakes in milliseconds, with every process where it was. It wakes on:

  • a new connection to it, such as a request to a published port
  • a docker command that acts on one of its containers, such as exec, attach, stop or restart
  • a file changed in its bind mounts

Commands that only read, such as docker ps, docker logs, docker inspect and docker stats, don't wake it.

Keeping a project awake

A schedule inside an app's own process, such as node-cron or a Go ticker, isn't seen as use. To keep a project awake, switch on Keep awake for it, or for any of its containers, in the app. From the menu bar you can also put a project to sleep or wake it now.

To keep it awake from the project itself, give any of its containers the label barely.sleep=false. In a compose file:

labels:
  barely.sleep: "false"

With docker run:

docker run -d --label barely.sleep=false redis

The label barely.sleep=true does the opposite: that container's own use doesn't count, and its project sleeps once everything else in it is quiet.

The VM hibernates

Once every project is asleep and nothing on your Mac has used the VM for idle_timeout (5 minutes by default), Barely saves the VM to disk and stops it. It then uses no memory. A docker command, a barely shell session and a connection to a published port each count as using the VM.

Barely keeps every published port listening on your Mac. The next docker command, or a connection to one of those ports, resumes the VM in under a second, with every container where it was.

With nothing running, the VM shuts down instead and saves nothing.

To hibernate now, click Hibernate on the app's Engine screen. In the terminal:

barely hibernate

Stopping the VM, from the Engine screen or with barely stop, and barely restart discard a hibernated VM, and the next start boots it fresh. So does a config change that needs a restart, such as cpus, memory_max, shares or the sleep settings.

Turn it off

barely config set sleep false

Then run barely restart. With sleep off, projects don't sleep and the VM doesn't hibernate. It only shuts down when nothing is running.

Questions

What happens to open connections while a project sleeps?

They stay open, and the next bytes sent on one wake the project. When every project is asleep and the VM hibernates, streams like docker logs -f end and need starting again.

Does the app keep the VM awake?

No. With the app open, projects still go to sleep and the VM still hibernates when idle. The app doesn't start a stopped VM unless you press Start.

How much disk does a hibernated VM take?

About as much as the RAM it was using. With nothing running, the VM shuts down instead and saves nothing.

Something missing or wrong? Tell us.