Update PolarBot
An update is: get the new source, build it, back up the database, keep the old binary, install the new one, start it. The database backup and the old binary are what make a rollback possible: a new version may add database migrations, and an older binary refuses to start on a database a newer one has migrated.
Read the Changelog first: it says what changed and whether anything needs your attention.
1. Get and build the new version
In the clone you installed from (Install, step 4):
cd ~/PolarSystems
OLD="$(git rev-parse HEAD)"
git fetch origin
git checkout stable
git pull --ff-only
git log -1 --oneline
export POLARBOT_CHANNEL=stable
export POLARBOT_GIT_REV="$(git rev-parse --short HEAD)"
export POLARBOT_BUILD_DATE="$(date -u +%Y-%m-%d)"
cargo build --release --locked -p polarbot
OLD remembers the commit you run now (the clone is still at the commit you last installed).
git pull --ff-only refuses to merge if your clone has local changes, so you never build
something you did not mean to. The build ends with a Finished line.
To see whether this update changes the database:
git diff --stat "$OLD" HEAD -- crates/polarbot/migrations
Any output means new migrations: after the update, rolling back needs the database backup from the next step.
2. Back up, keep the old binary, install
sudo systemctl stop polarbot
STAMP="$(date -u +%Y%m%dT%H%M%SZ)"
sudo install -d -m 0700 /var/backups/polarbot
sudo cp -a /var/lib/private/polarbot/polarbot.db "/var/backups/polarbot/polarbot-$STAMP.db"
sudo cp -a /var/lib/private/polarbot/polarbot.db-wal "/var/backups/polarbot/polarbot-$STAMP.db-wal" 2>/dev/null || true
sudo cp -a /var/lib/private/polarbot/polarbot.db-shm "/var/backups/polarbot/polarbot-$STAMP.db-shm" 2>/dev/null || true
sudo cp -a /opt/polarbot/polarbot /opt/polarbot/polarbot.prev
sudo install -m 0755 target/release/polarbot /opt/polarbot/polarbot
- The bot is stopped first, so the database is not written while it is copied.
- The database lives in
/var/lib/private/polarbot(systemd’s private directory forDynamicUserservices;/var/lib/polarbotpoints there). The-waland-shmfiles are SQLite’s write-ahead log; they exist only sometimes and are copied along when they do. /opt/polarbot/polarbot.previs the binary you are replacing.
If the unit file changed in this release (git diff "$OLD" HEAD -- deploy/polarbot.service
prints something), install it too:
sudo install -m 0644 deploy/polarbot.service /etc/systemd/system/polarbot.service
sudo systemctl daemon-reload
(If you removed the OAuth credential lines from your unit, remove them again.)
3. Start and check
sudo systemctl start polarbot
sudo journalctl -u polarbot -n 30 --no-pager
The first line shows the new version and commit (starting polarbot version="…" rev="…"),
then connected and registered global commands. /about in Discord shows the same version.
About 30 seconds after the start, each server gets one “PolarBot updated to vX.Y.Z” notice
with that version’s changelog, in its staff announcements channel (once per version, never
again after a restart).
Old backups are not deleted automatically by these steps; install.sh (below) keeps the 10
newest. To do the same by hand:
ls -1t /var/backups/polarbot/polarbot-*.db | tail -n +11
lists the ones beyond the 10 newest; delete them (with their -wal/-shm files) with
sudo rm.
Shortcut: the install script
Steps 2 and 3 are exactly what deploy/install.sh does (and it keeps the 10 newest backups):
cp target/release/polarbot ./polarbot
sudo ./deploy/install.sh
It never touches an existing /etc/polarbot/config.toml and does not ask for credentials that
already exist. It always installs the unit from deploy/, so if you edited your unit, put your
changes in a drop-in instead (sudo systemctl edit polarbot).
The maintainers update from a workstation with deploy/deploy.sh <ssh-host>, which copies the
committed source to ~/deploy/polarbot/src on the server and builds it there; then
cd ~/deploy/polarbot/src && sudo ./deploy/install.sh on the server.