Build your room

Keeping the room online 24/7

Where to host, how much machine you need, systemd or PM2, updates and what we learned keeping rooms online.

Running the room on your PC is great for testing. For it to stay online day and night, you need a server (VPS) that is always on. This page shows the path we used.

How much machine you need

Numbers measured on the BonkTools rooms (Node 22, Linux):

RoomMemory (RSS)CPU
Pick with automatic score and rec~200–250 MBlow (spikes at the end of the match)
Room with the AI playing (2 simulations: score and "eyes")~450 MB1 core handles 1–2 rooms

A VPS with 1 core and 1 GB handles a pick room. With 2 cores and 4–6 GB, several rooms and the Discord bot fit.

Preparing the server (Ubuntu)

bash
# Node.js 22
curl -fsSL https://deb.nodesource.com/setup_22.x | sudo -E bash -
sudo apt-get install -y nodejs git

# the project (from your git, or upload the zip with scp)
git clone https://github.com/you/minha-sala.git ~/minha-sala
cd ~/minha-sala
npm ci
nano .env        # account, room name, Discord...

systemd already comes with Ubuntu: it starts the room on boot and restarts it if the process dies. Create /etc/systemd/system/minha-sala.service:

ini
[Unit]
Description=My bonk.io room
After=network-online.target
Wants=network-online.target

[Service]
User=ubuntu
WorkingDirectory=/home/ubuntu/minha-sala
ExecStart=/usr/bin/npx tsx src/index.ts
Restart=always
RestartSec=5
Environment=NODE_ENV=production
# safety limits
MemoryMax=800M
NoNewPrivileges=true

[Install]
WantedBy=multi-user.target
bash
sudo systemctl daemon-reload
sudo systemctl enable --now minha-sala     # start now and on every boot
systemctl status minha-sala                # is it running?
journalctl -u minha-sala -f                # live logs (the room link shows up here)
sudo systemctl restart minha-sala          # after changing .env or the code

Option 2: PM2

bash
sudo npm install -g pm2
pm2 start "npx tsx src/index.ts" --name minha-sala
pm2 save && pm2 startup     # follow the instruction it prints
pm2 logs minha-sala

Several rooms

  • Same code, different settings: create .env.sala2 and a second service with ExecStart=/usr/bin/node --env-file=.env.sala2 --import tsx src/index.ts.
  • One account, several rooms: it works. BonkSession spaces out room creation so it doesn't hit the server's limit.
  • Each room with automatic score runs the physics in its own worker: count ~200 MB per room.

Updating without kicking anyone out

Restarting the room with people playing kicks everyone out. What we did:

  1. The room exposes how many players it has (a local /status, or just a file updated every minute).
  2. An update script does git pull && npm ci, waits for the room to be empty and only then restarts.
bash
#!/bin/bash
cd ~/minha-sala && git pull --ff-only && npm ci
until [ "$(cat jogadores.txt 2>/dev/null)" = "0" ]; do sleep 30; done
sudo systemctl restart minha-sala

(In the example, write room.state.players.size - 1 to jogadores.txt ("players") on every join and leave.)

What we learned along the way

  • bonk.io can ban the room's account. In October 2026 our rooms' accounts were banned all at once. Have a plan B: let the room work as a guest and keep a list of alternative names.
  • Memory leaks kill rooms slowly. Every player who joins opens a WebRTC connection; in an old version of the library they weren't closed when the person left, and the room went from 12% to 86% CPU in 40 minutes. Use bonktools 0.2.7 or newer and keep an eye on memory (systemctl status shows it).
  • A watchdog helps. A timer that checks every minute whether the room responded recently, and restarts it if the CPU stays pinned high for 3 minutes, saved many hours of downtime.
  • Editing mistakes in .env bring the room down. One extra character at the start of the file left one of our rooms in an endless restart loop for 3 hours. Make a copy before editing and check the log after restarting.
  • Secrets out of git. .env, Discord tokens and keys never go into the repository. If one leaks, rotate it right away.
  • Server access. Use an SSH key (never a password) and, if you can, leave port 22 open only to your IP or behind a VPN.