Docs / How-to guides

Move your Otto server to a new machine

Copy everything your Otto server holds to a new machine and switch over to it: run one command on your Mac and answer its questions. The old server is left as it was until you delete it.

Before you start

Below, replace NEW_IP with the new server's IP address, OLD_IP with the old one's, and example.com with your domain. Your sessions are paused from the start of the move until its end. The move leaves out what an install or a build makes again, such as node_modules; each session reinstalls its dependencies when it next starts.

Before you move

Do this once, a day before the move.

  1. Give the server a name

    At your DNS provider, add an A record vps.example.com pointing at OLD_IP.

  2. Point your Macs at the name

    On every Mac, in ~/.ssh/config, set the HostName line under Host otto-vps:

    HostName vps.example.com

    Then run ssh otto-vps true once, and answer yes if it asks: it is the same server under its new name. From now on, your Macs follow the server through DNS.

  3. Lower the TTLs

    At your DNS provider, set the TTL of every domain name your server uses, and of vps.example.com, to 300 seconds. To list the names:

    ssh otto-vps sudo bash /opt/otto/deploy/session-host/server-move.sh names

    The old TTL must run out before the new one counts, so do this a day ahead. A short TTL makes the switch take minutes instead of hours.

  4. Check the new server (optional)

    scp deploy/session-host/server-move.sh root@NEW_IP:
    ssh root@NEW_IP bash server-move.sh preflight

    It prints one PASS, WARN or FAIL line per check, and changes nothing. Fix each FAIL. The move runs the same check first anyway.

Move

  1. Start the move

    On your Mac, in your Otto checkout, run:

    bash deploy/session-host/server-move.sh

    It asks, each with a default in brackets that Enter takes:

    • the alias your Mac reaches the old server with, otto-vps by default;
    • the new server's IP address, NEW_IP;
    • if your alias still has an IP address, whether to give the server a name. Say yes, and take vps.example.com or type your own.

    It then shows the steps as a checklist, with how long each takes, and warns about a TTL still above 600 seconds. Answer y to go ahead. Your sessions pause from step 3 until step 10.

  2. Type root's password, if it asks

    Only when the new server does not take your Mac's key yet. Type its root password once; the move adds your Mac's key with it, and nothing asks again.

  3. Wait for the copy and the import

    The move ticks off each step as it finishes. It checks the new server, drains and exports the old one, copies the export from server to server, and installs Otto on the new server. This takes about half an hour. Each session is paused once its turn is over, with its conversation kept. A session still busy after 5 minutes is interrupted, unless it is in a git operation or an Otto vault edit, which is waited for up to 30 more minutes. The old server is fenced: Otto stays off there, even after a reboot.

  4. Point your domain names at the new server

    When it says ▲ Your turn, it lists the domain names your server uses, vps.example.com among them. At your DNS provider, point each one at NEW_IP: change its A record, and remove any AAAA record that points at the old server.

    The move checks every 30 seconds and carries on by itself once every name gives the new address. You can press Ctrl-C and run it again later.

  5. Flush your Mac's DNS cache, if it asks

    If your Mac still has the old address cached, the move offers to flush it. Answer y and type your Mac's password for sudo. Otherwise ssh otto-vps could reach the old, fenced server for a while.

  6. Resume your sessions: the point of no return

    The move has verified the new server and stopped the old one's website. Until now you can still go back to the old server, losing nothing. Once your sessions resume on the new server, their work happens there only, and going back would lose it. When you answer y, the move records this on the old server, whose undo-export then refuses.

    It resumes your sessions one at a time, each told it was paused for maintenance, and reports how many resumed, naming any that did not yet. A background job a session was waiting on, such as a dev server, ended with the old server: the session is told to run it again.

  7. Keep or delete the export's copies

    The export is still on both servers, and it holds your keys. Answer n to keep it for a few days; the move prints the two commands that delete it. Answer y to delete it now.

  8. Reconnect the CI runner

    Skip this step if you never registered a self-hosted runner. Otherwise, on GitHub open your repository's Settings → Actions → Runners → New self-hosted runner, copy the --token value, and run the command the move printed:

    ssh -t otto-vps sudo bash /opt/otto/deploy/session-host/vps-deploy.sh runner-register

    Paste the token when asked. Then remove the old, offline runner on the same GitHub page.

You're done when it says Moved. Your other Macs follow by themselves. After a few days on the new server, delete the old server.

Without a server name, the move changes only this Mac's HostName, to NEW_IP, and keeps a backup. Change it by hand on your other Macs. If Otto's Settings → Session hosts names the server by its address, change it there too.

Carry on or start over

Each step runs once. If the move stops, or you press Ctrl-C, fix what it says and run bash deploy/session-host/server-move.sh again: it offers to carry on, and opens at the step it stopped at. Its progress is kept in ~/.otto/server-move/otto-vps/ on your Mac.

To start over, answer n to carrying on and y to starting over, or add --restart. An export that was already made on the old server is kept.

Move with flags (scripted)

The same move, with the answers given as flags. To see the plan first, changing nothing:

bash deploy/session-host/server-move.sh move NEW_IP --dry-run

Then run it:

bash deploy/session-host/server-move.sh move NEW_IP --from otto-vps --server-name vps.example.com

--yes answers yes to every question but deleting the export's copies, which it keeps. Root's password can come from --password-file or OTTO_MOVE_PASSWORD. Every option is in the reference.

Move step by step (fallback)

The same move, one command at a time, run on the servers. Use it when you can't run move from a Mac. Below, replace SERVER and NEW_IP with your own values.

Do Before you move first. Your sessions are paused from step 2 until step 7. To see what step 2 will copy and whether it fits on the old server's disk, first run it with --dry-run. It leaves out what an install or a build makes again, such as node_modules; each session reinstalls its dependencies when it next starts.

  1. Check the new server

    scp deploy/session-host/server-move.sh root@NEW_IP:
    ssh root@NEW_IP bash server-move.sh preflight --need-bytes BYTES

    Replace BYTES with the EXPORT_BYTES value that export --dry-run prints on the old server, or leave --need-bytes out. Fix each FAIL before you go on.

  2. Export the old server

    ssh SERVER
    sudo bash /opt/otto/deploy/session-host/server-move.sh export --drain

    It first drains the server: each session is paused once its turn is over, with its conversation kept, and nothing new starts. A session still busy after 5 minutes is interrupted, unless it is in a git operation or an Otto vault edit, which is waited for up to 30 more minutes. Then it exports, and fences the server so Otto stays off there. It ends with export done.

    If a session is still mid-turn when the wait ends, it refuses. Let that session finish, or stop it, and run the command again.

  3. Copy the export to the new server

    On your Mac, through your Mac:

    scp -3 -r SERVER:otto-move root@NEW_IP:
  4. Import it on the new server

    ssh root@NEW_IP
    bash otto-move/server-move.sh import

    It ends with import verified and lists the domain names your server uses. The new server now answers with the old one's SSH host keys.

  5. Point your domain names at the new server

    At your DNS provider, point each name the import listed, and the server's own name, at NEW_IP: change its A record, and remove any AAAA record that points at the old server.

  6. Check the new server through your Mac

    If your alias uses the server's name, it follows DNS. Otherwise, on each Mac, change the HostName line under Host SERVER to NEW_IP, and change Otto's Settings → Session hosts if it names the server by its address. Then run:

    ssh SERVER sudo bash /opt/otto/deploy/session-host/server-move.sh verify

    Run it again until it ends with verified; DNS changes can take a while to arrive.

  7. Resume your sessions

    This is the point of no return: from here on, going back to the old server would lose what the sessions do on the new one. First stop the old server's website and record the move there, so its undo-export refuses:

    ssh -o HostName=OLD_IP SERVER sudo bash /opt/otto/deploy/session-host/server-move.sh stop-web
    ssh -o HostName=OLD_IP SERVER sudo bash /opt/otto/deploy/session-host/server-move.sh moved-to NEW_IP

    The drain moved with the server, so the new server still starts nothing. Undrain it and resume what the drain paused:

    ssh SERVER sudo bash /opt/otto/deploy/session-host/server-move.sh undrain

    The sessions resume one at a time, and each is told it was paused for maintenance. It reports how many resumed. Or click Undrain in Otto's Settings → Session hosts, with Resume the sessions the drain paused ticked.

  8. Reconnect the CI runner

    Skip this step if you never registered a self-hosted runner. Otherwise, on GitHub open your repository's Settings → Actions → Runners → New self-hosted runner, copy the --token value, and run:

    ssh -t SERVER bash /opt/otto/deploy/session-host/vps-deploy.sh runner-register

    Paste the token when asked. Then remove the old, offline runner on the same GitHub page.

You're done. After a few days on the new server, delete the old server and the otto-move folder on the new one. The folder holds your keys.

If something goes wrong

If the move stops with an error, fix what it says and run it again. It carries on where it stopped.

Until you delete it, the old server still holds everything. Before your sessions resume on the new server, you can go back to it losing nothing. To go back, point DNS, the server's name included, at the old server's address again. Without a server name, change HostName back too: the move kept a backup of ~/.ssh/config next to it. Then run, with your alias for SERVER:

ssh SERVER sudo bash /opt/otto/deploy/session-host/server-move.sh undo-export

It lifts the fence, starts Otto there again, its website included, and lifts the drain, resuming the sessions it paused one at a time.

Once your sessions have resumed on the new server, undo-export refuses: the old server would come back as it was at the export, without the work done since. Add --force only if you mean to lose that work.