Docs / How-to guides

Drain a session host for maintenance

Bring every session on your Otto server to a safe stop before you restart, resize or move it. Afterwards, undrain it and the sessions resume where they left off.

Before you start

A drain pauses every session on the host, keeps its conversation, and starts or resumes nothing until you undrain. Each session gets 5 minutes to finish its turn. A session still busy after that is interrupted, unless it is in the middle of a git operation or an Otto vault edit: that one is waited for, up to 30 more minutes, and never cut. See the reference for the exact rules.

You can drain from Otto on a Mac, from the web app, or on the server. Below, replace SERVER with the name your Mac uses to SSH to your Otto server.

Steps

  1. Start the drain

    In Otto, open Settings → Session hosts, find the server and click Drain. You can change the grace period and the hard timeout there first.

    Or, on the server:

    ssh SERVER
    docker exec otto-host otto-as-service node /otto-host-exec/otto-host.js drain --by "maintenance at the server" --wait

    --wait prints a line at each change and returns once every session is paused. Add --grace <min> or --hard <min> to change the defaults.

  2. Wait until it is drained

    Settings → Session hosts shows the drain's progress. It is done when it says Drained. On the server:

    docker exec otto-host otto-as-service node /otto-host-exec/otto-host.js drain status

    The summary starts with Drained: and phase is drained. A swarm's workers may still run to their end; nothing new starts.

  3. Do your maintenance

    The drain survives a restart of the container, the server, or a move to a new server. Until you undrain, Otto refuses launches and resumes on this host with a message that says it is draining.

  4. Undrain and resume

    In Settings → Session hosts, click Undrain with Resume the sessions the drain paused ticked. Or, on the server:

    docker exec otto-host otto-as-service node /otto-host-exec/otto-host.js undrain --resume

    The sessions resume one at a time, about one every 20 seconds, while the host has memory, disk and a free session slot. Each is told it was paused for maintenance and asked to check git status before it carries on.

You're done. To undrain without resuming anything, leave the box unticked (or drop --resume); the sessions stay on Paused and get the same note whenever you resume them.

If the drain is stuck

The status says Drain stuck: when a session is still in a step that must not be cut after the hard timeout. The summary names each such session and its step, such as git rebase or a git merge in progress. Otto never cuts it. Either:

A step stopped halfway in a checkout, such as a rebase with conflicts, keeps the session held even when nothing runs. Resolve or abort it in that worktree.

A session listed with an error could not be interrupted or paused; the drain tries again every few seconds. If it keeps failing, check the broker's log: docker logs otto-host 2>&1 | grep drain.

To give up on the drain, undrain. Sessions it paused stay paused until you resume them.