Upgrades & draining
This page covers moving to a new release: replacing the binary, applying schema changes, and stopping the old process cleanly.
Before you upgrade
Section titled “Before you upgrade”- Read the release notes on GitHub for the version you are moving to.
- Back up the database and the identity key. See Identity keys.
- Check that your config file has no keys the new version does not know: an unknown key stops the server at
startup.
config.example.yamlin the new release lists every key.
Upgrade the .deb
Section titled “Upgrade the .deb”VERSION=1.1.0BASE=https://github.com/stephanfeb/go-ricochet/releases/download/v${VERSION}curl -LO "$BASE/ricochet-server_${VERSION}_amd64.deb"curl -LO "$BASE/SHA256SUMS"sha256sum --check --ignore-missing SHA256SUMS
sudo apt install ./ricochet-server_${VERSION}_amd64.debThe package handles the restart:
- Before the files change, it notes whether the server is running and stops it through supervisord.
- It installs the new binary,
run.sh,health_check.shandschema.sql. - It keeps your
/etc/ricochet/config.yamland/etc/supervisor/conf.d/ricochet.conf(both conffiles) and your/etc/ricochet/env, and resetsconfig.yamlandenvto mode 640, ownerroot:ricochet. - If the server was running before, it starts it again on the new binary. A server that was stopped stays stopped.
If the restart fails, the package prints a warning pointing at supervisorctl tail ricochet stderr.
Upgrade a manual install
Section titled “Upgrade a manual install”Stop the server, replace the binary, apply the schema, start it:
sudo supervisorctl stop ricochet # or your own supervisorsudo cp ricochet_1.1.0_linux_amd64/ricochet /usr/local/bin/ricochetpsql -h localhost -U ricochet -d ricochet -f ricochet_1.1.0_linux_amd64/schema.sqlsudo supervisorctl start ricochetKeep the old binary until the new one has run cleanly.
Schema changes
Section titled “Schema changes”The server never changes the schema itself. Schema changes ship in schema.sql, which is written to be run again
on an existing database:
- Tables and indexes are created with
IF NOT EXISTS. - Columns added to existing tables are in an “in-place upgrades” section near the end, with
ADD COLUMN IF NOT EXISTSand, where needed, a backfill of existing rows. - The grants at the end are re-applied.
So on every upgrade, run the new release’s schema.sql against your database, as the database owner or a
superuser, before you start the new binary. Running it when nothing changed is harmless. There are no numbered
migrations and no down-migrations: to roll back, restore your database backup.
The .deb does not run schema.sql for you. It installs it at /opt/ricochet/schema.sql:
psql -h localhost -U ricochet -d ricochet -f /opt/ricochet/schema.sqlGraceful shutdown
Section titled “Graceful shutdown”On SIGTERM or SIGINT, the server shuts down in this order:
- Withdraws from load balancing.
/readyzstarts returning 503 with"draining":true, and the server logsops surface draining — /readyz now reports unready. - Waits
ops.drain_delay(default 0) while still serving, loggingdraining before shutdown. This gives a load balancer polling/readyztime to take the instance out of rotation. - Refuses new requests with a 503 in each protocol’s own error format, and waits up to
ops.shutdown_timeout(default 5 s) for requests already in flight. It logsin-flight requests drained, orshutdown timeout reached with requests still in flightif the timeout ran out. - Tears down background services, the libp2p host, the ops listener, and finally the database pool, and
logs
server stopped.
A second signal during this sequence forces an immediate exit with code 130 (SIGINT) or 143 (SIGTERM), and
logs forced shutdown: second signal arrived before the graceful stop finished. A shutdown that fails exits with
code 1.
ops: drain_delay: 20s # behind a load balancer: a couple of probe intervals shutdown_timeout: 5sSet your supervisor’s kill timeout above drain_delay + shutdown_timeout plus a few seconds for teardown. The
.deb’s supervisord config waits 30 seconds (stopwaitsecs=30), which covers the defaults; raise it if you set a
long drain_delay.
Check it works
Section titled “Check it works”ricochet --version # or /opt/ricochet/ricochet_server --versioncurl -s http://127.0.0.1:9090/readyzgrep 'running. Peer ID' /var/log/ricochet/stdout.log | tail -n 1The startup line shows the new version, and the peer ID should be unchanged.
Troubleshooting
Section titled “Troubleshooting”- The new version will not start:
parse config file: ... field X not found: the key was removed or renamed. Delete or rename it. Alogging:block from before v1.0.0 is a common case; delete it. - Errors about a missing column after the upgrade: the new
schema.sqlwas not applied. Run it. - The server was running before the
.debupgrade and is now stopped: the restart failed. Checksupervisorctl tail ricochet stderr, fix the cause and start it. - Clients see a burst of failures during each restart: set
ops.drain_delayand point the load balancer’s health check at/readyz.