Skip to content

Upgrades

Shaken Fist supports online upgrades natively -- when an object is read from MariaDB with an older version number, the object is upgraded silently to the newest version. If all nodes in your cluster are running a version of Shaken Fist which supports this newest version, the upgraded object is then written back to MariaDB. If not all nodes in the cluster support the new version, the new version is simply used in memory by the node which did the upgrade. This means it is safe to perform a rollout across a cluster without downtime, although you might see small transient failures such as single API requests failing as processes restart.

That describes an old object read by a new node. The other direction is not symmetrical, and it is worth knowing about before you plan a rollout. A node which has been upgraded creates objects at the new version immediately -- the cluster minimum governs whether an upgraded object is written back, not what a new object is created as -- so for the length of a rollout a not-yet-upgraded node may read a row it does not understand. There is no downgrade step and never will be, so that read fails, with a log line naming the object, the version it is stored at and the version that node understands:

Object <uuid> is version 4, but this node only understands version 3 of
object type agentoperation

The practical consequences:

  • Only an object type whose version actually moved in the release you are installing is affected, and only for objects created during the rollout. Most releases bump no object versions at all.
  • The exposure is worst where the writing and reading nodes are reliably different machines. An agent operation, for example, is created by sf-api and read by sf-sidechannel on the instance's hypervisor, so agent operations created during the rollout fail on hypervisors that have not been upgraded yet.
  • The failure is loud rather than silent: nothing is written at the wrong version, and it works once that node is upgraded. Retry after the rollout.
  • It is not confined to operations on that one object. An object is upgraded as it is loaded, so on a not-yet-upgraded node a listing, or a daemon's periodic sweep, which happens to load one newer object fails as a whole until that node is upgraded.

So the advice is the same advice as always -- do not leave a cluster half-upgraded for longer than you have to -- but the reason is now written down rather than discovered.

You should note however that "all nodes" includes nodes in non-running states such as ERROR and MISSING. The only state which is excluded from the check is DELETED. Therefore, in order for online upgrades to work correctly, it is important that you delete nodes in an ERROR or MISSING state that you are confident will not return to the cluster. This is because nodes can return from ERROR or MISSING at the end of planned maintenance, and might be running and older version of Shaken Fist upon their return than other members of the cluster.

Upgrading to v0.8.0

Releases before v0.8.0 wrote AUTH_SECRET_SEED, MARIADB_PASSWORD and LOKI_AUTH_HEADER into the daemon logs in plaintext on every sf-queues start, and a blob transfer's authorisation token into an audit event on every transfer. Upgrading stops that happening but cannot undo it. See Credential rotation for how to confirm the exposure on your own cluster, and what to rotate.

Upgrade process

First off, upgrade the python packages in each node's virtualenv manually. This is explicitly a non-goal of our deploy tooling as we believe different deployments will have different strategies for performing this step. Naively, a good first approach is simple to run this command on each node:

sudo /srv/shakenfist/venv/bin/pip install --upgrade shakenfist

Which will pull in all the relevant other python packages it requires.

Then simply re-run your deployment playbook as you did when you first installed (see Installation) and the cluster will upgrade.

If your inventory has a kerbside group, refresh the control node's collections before that re-run:

ansible-galaxy collection install --force -r examples/_shared/requirements.yml

A Shaken Fist release can raise the shakenfist.kerbside range that requirements.yml pins, and the playbook refuses to deploy Kerbside when the installed collection falls outside it. Refreshing first turns that into a command you ran deliberately rather than a failed play. See Installation for the detail.

If you deploy with the shakenfist.shakenfist Ansible collection, re-running the playbook is restart-on-change: the node role restarts a node's sf-* daemons only when the installed code, /etc/sf/config, or a systemd unit actually changed on that node. A redeploy on a day nothing moved leaves the running cluster undisturbed, so it is safe to run the deploy on a schedule; on a day the code did move, the daemons restart to pick it up (a built-in daily upgrade-path test). Code changes are detected by hashing the installed package files, not the wheel, so a rebuilt-but-identical wheel does not trigger a spurious restart. See the collection's Idempotence and restart-on-change section for details. This automates, per node, the same restart the manual procedure below performs by hand.

Free page reporting applies to new instances

An upgrade never rewrites the libvirt domain XML of an instance that already exists. A libvirt domain definition is persistent, and Shaken Fist renders the domain template only when the hypervisor has no definition for that instance, so a power off and power on, a hypervisor reboot, or a redeploy shipping a newer template all leave an existing instance on the XML it was created with.

This matters for free page reporting, added in this release: an instance created before the upgrade keeps its old, non-reporting balloon device and continues to hold its high-water mark of host memory until it is deleted and recreated. Long-lived instances are both the ones this affects most and the ones that stand to gain most from it, so it is worth deliberately recycling them if host memory pressure is what prompted the upgrade.

There is a manual route if recreating an instance is not acceptable: power the instance off, undefine the domain on its hypervisor with virsh undefine sf:<instance uuid> (add --keep-nvram for a UEFI instance, so its boot variables survive), and power it back on, at which point Shaken Fist re-renders the template. Understand what that gives up before reaching for it. It is the same code path a failed power on retry uses, and it discards any libvirt-side state carried in the existing definition. Recreating the instance is the supported route; this is a workaround, and it is on you to confirm the instance comes back.

Discard applies to new instances

Instance disks are now created with discard='unmap', so a guest's fstrim (or online discard mount option) reaches the image file and the space is actually returned to the hypervisor's filesystem. Previously qemu's default of discard='ignore' accepted those requests and dropped them, so an instance's disk allocation only ever grew towards its full provisioned size however little data the guest held. The detail is in IO performance tuning.

This is subject to the same persistent-domain limitation as free page reporting above: an instance created before the upgrade keeps the domain XML it was created with, and keeps dropping its guest's trims, until it is deleted and recreated. The same virsh undefine workaround applies, with the same caveats.

Recreating an instance is the only reclaim path Shaken Fist offers. Nothing here runs virt-sparsify or otherwise rewrites an existing image, and you should not run such a tool against a running instance's disk. Once a recreated or new instance is running, the reclaim is the guest's to make: nothing in Shaken Fist trims on its behalf, so an image shrinks when the guest's own fstrim runs. Expect host allocation for those instances to fall rather than rise from that point, which is a change in what the free space on a hypervisor's instance filesystem does over time.

UEFI instances and the 4 MB OVMF firmware

UEFI firmware comes in two flash sizes, and a firmware image only boots with an NVRAM file of its own size. Debian 12 and Ubuntu 22.04 ship both sizes; Debian 13 and Ubuntu 24.04 ship only the 4 MB images. Shaken Fist used to hard-code the 2 MB images, so UEFI instances did not start at all on the newer distributions.

It now picks the firmware when it renders the domain XML:

  • a new UEFI instance gets the 4 MB firmware wherever it is installed, which is every supported distribution;
  • an instance that already has an NVRAM file, or was created from an nvram_template blob, gets the firmware whose size matches it, so instances created with the 2 MB firmware keep booting on a hypervisor that still has it.

Moving a hypervisor from Debian 12 to Debian 13, or from Ubuntu 22.04 to Ubuntu 24.04, removes the 2 MB images. That breaks any UEFI instance created before the upgrade, twice over:

  • its persistent libvirt definition names the 2 MB firmware path directly, as described above;
  • its NVRAM is 2 MB, so even a re-rendered domain has no firmware to pair it with, and power on fails with an error saying so.

Recreate those instances after the upgrade. If that is not acceptable, keep the 2 MB images installed on the upgraded hypervisor, for example by copying /usr/share/OVMF/OVMF_CODE.fd, OVMF_CODE.secboot.fd, OVMF_VARS.fd and OVMF_VARS.ms.fd from the older release's ovmf package. Treat those copies as unmanaged files that will not receive security updates.

UEFI instances with a SCSI disk

A UEFI instance with a bus=scsi disk never booted before this release: it got libvirt's default LSI Logic controller, which OVMF has no driver for, so the firmware found no disk and dropped to the EFI shell. Such instances now get a virtio-scsi controller instead. As with every other domain template change, the persistent definition of an existing instance is not rewritten, so an affected instance has to be recreated (or its domain undefined, as described above) before it can boot. BIOS instances are deliberately left on the LSI Logic controller, which SeaBIOS can boot and which is the only controller some appliance images carry a driver for.

Network nodes need the iptables conntrack match

Since the release which made floating addresses answer from inside their own network, a NAT providing network's namespace carries a hairpin masquerade rule matched with -m conntrack --ctstate DNAT. A network node whose kernel lacks xt_conntrack will fail to install that rule, and the network will not come up there at all.

Every stock Ubuntu and Debian kernel has it, so this is only a concern if you run a custom kernel. Check before you roll the daemons:

iptables -m conntrack --help > /dev/null && echo ok

See the floating IP discussion in the networking overview for what the rule does and why both of its matches are needed.

Errored cluster operations drain on the first sweep

Earlier releases never hard deleted a cluster operation which finished in error, so a cluster which has been running for a while holds every one it has ever had. This release removes them on the same window as any other finished operation, CLUSTER_OPERATION_RETENTION (15 minutes by default; see the deleted-object sweep), and the whole accumulation becomes eligible as soon as the new cluster daemon runs.

Expect the cluster_deleted_object_backlog gauge for the *_op types to jump within an hour of the upgrade, by roughly the number of errored operations the cluster had kept, and then to fall as the sweep drains them within its DELETED_OBJECT_SWEEP_SECONDS budget each minute. Do not page on that rise for the first few hours. It is a one-time cost: what matters is that the gauge falls, and a backlog which is still climbing a day later is a sweep that is not keeping up, as described under Watching for sweeps that silently do nothing. The gauge counts operations, but most of the work is in their events. A hard delete removes an operation's object_states, object_metadata, cluster_operations, target and error rows, and also its event_objects rows, after which the orphaned-events sweep removes the events rows themselves (counted in database_orphan_events_pruned_total, which will rise too). That includes each errored operation's audit, queue-wait and duration events. If you want any of those kept, export them before you upgrade; after the first sweeps they are gone.

To see how large the drain will be before you upgrade, count both:

SELECT object_type, COUNT(*) FROM object_states
WHERE state_value = 'error' AND object_type LIKE '%\_op'
GROUP BY object_type;

SELECT s.object_type, COUNT(*) FROM object_states s
JOIN event_objects e
  ON e.object_type = s.object_type AND e.object_uuid = s.object_uuid
WHERE s.state_value = 'error' AND s.object_type LIKE '%\_op'
GROUP BY s.object_type;

The second number, not the first, is what sizes the delete, binlog and lock load of the drain.

The SPICE TLS private key is no longer world readable

Earlier releases of the internal_ca role installed each node's SPICE TLS private key, /etc/pki/libvirt-spice/server-key.pem, as root:root 0444. Any local user on a hypervisor could read it, and with it impersonate that hypervisor's SPICE endpoint to a client which trusts the cluster CA, Kerbside's connection to the hypervisor included. The cluster CA's own key never leaves the control node, so it was not exposed.

The role now installs the key root:kvm 0440. QEMU opens the key itself, running as libvirt-qemu, whose primary group is kvm on every supported distribution. Redeploying corrects the mode and group of an existing key in place; check afterwards with:

stat -c '%a %U:%G' /etc/pki/libvirt-spice/server-key.pem

which should print 440 root:kvm. If you call the role from your own playbook and pass cert_group or cert_key_mode for the SPICE certificate, review those values: a key QEMU cannot read stops SPICE TLS, and with it every instance start, on that hypervisor.

The certificate goes to every node, not only hypervisors, so every node now needs a kvm group. udev creates it, and every supported distribution installs udev; a node without one, a minimal or container-based install say, fails the deploy with a message naming cert_group before anything is installed on it.

Redeploying does not replace the key, which was readable before the upgrade. If you have local users on your hypervisors you do not trust with it, rotate it: on the control node, remove both /srv/shakenfist/pki/CA/<node>-server-key.pem and /srv/shakenfist/pki/CA/<node>-server-cert.pem for each node (removing only the key leaves a certificate which no longer matches it), then redeploy. An instance keeps the certificate it started with until it is next powered off and on.

Federated issuers: JWKS redirects and the rotation cooldown

This release moves to PyJWT 2.14, which changes two things an operator using identity federation can see. Neither needs action unless it describes your provider.

Redirects are no longer followed when fetching an issuer's JWKS, so a jwks_uri which answers 301 or 302 — one pointing at a CDN path rather than serving the key set itself — stops working, and every exchange against that issuer answers 401. Reconfigure the issuer with the final URL. See the JWKS URI must be the final URL for how to tell this apart from an unreachable provider.

A refetch forced by an unrecognised key id is now rate limited to one per FEDERATION_JWKS_ROTATION_COOLDOWN_SECONDS (default 30) per issuer, which means a key rotation landing inside that window is not recognised until it elapses. This is deliberate — /auth/federated takes no credential, so before it every invented key id a stranger sent bought another JWKS fetch made by us — but if you rotate often enough for the delay to matter, lower the setting or set it to 0 for the previous behaviour. See when an issuer rotates its signing keys.

Both settings are now range checked, and that check runs at import of shakenfist.config — which every daemon does, not just sf-api. FEDERATION_JWKS_CACHE_SECONDS must be at least 1 and FEDERATION_JWKS_ROTATION_COOLDOWN_SECONDS at least 0. A nonsensical value previously broke only federated exchanges, with a 500 per attempt and an otherwise working cluster; after this upgrade no daemon on that node starts at all. That is the better failure — a configuration error should not wait for somebody's first federated login to surface — but check /etc/sf/config for both settings before rolling the daemons.

The JWKS fetch timeout must now be at least 1

FEDERATION_JWKS_FETCH_TIMEOUT_SECONDS is now range checked like its three siblings, and that check runs at import of shakenfist.config — which every daemon does, not just sf-api. A value of 0 previously started the daemons and then refused every federated exchange, because zero makes each socket operation non-blocking rather than meaning "no timeout"; it now stops the daemons from starting at all. That is the better failure, but check /etc/sf/config for the setting before rolling the daemons.

The same release gives the JWKS fetch the two guards the discovery fetch has had since it was written: FEDERATION_JWKS_MAX_BYTES (default 65536) bounds the body, and the timeout above now also applies as a deadline over the whole transfer. An issuer whose jwks_uri serves something which is not a key set — a login page, or a document larger than the cap — now fails fast with the setting named in the sf-api log, where it previously read as an exchange which hung. See a provider which answers slowly, or enormously.

MariaDB schema migrations

Starting with v0.8, Shaken Fist uses MariaDB to store object state data. The MariaDB schema is versioned; migrations must be applied by an operator (or operator automation) before starting sf-database.

Each MariaDB table has a version number tracked in the schema_versions table. When the cluster is deployed or upgraded, the sf-ctl ensure-mariadb-schema command must be run on a node with direct database access to:

  1. Perform a compatibility check against the server requirements (MariaDB not MySQL, version >= 10.11.0, InnoDB engine, utf8mb4 charset and collation) — the command refuses to proceed if any check fails
  2. Create any missing tables
  3. Apply any pending schema migrations to bring tables up to the current version

sf-database also performs the same compatibility check at startup and will refuse to start if the server is incompatible. Importantly, if sf-ctl ensure-mariadb-schema has not been run after an SF upgrade that includes schema changes, sf-database will refuse to start with a clear schema-version mismatch error that names the command to run. This replaces the old behaviour where migrations ran silently inside the daemon on startup.

See MariaDB compatibility requirements in the database reference for the full list of server requirements.

Migrations run while the cluster is serving

sf-ctl ensure-mariadb-schema runs before any node restarts onto the new code, so every daemon in the cluster is still reading and writing the tables it migrates. A migration which has to rewrite existing rows — adding a column and filling it from somewhere else, for example — therefore does so in batches, each of which is a separate transaction covering a bounded range of the table. A concurrent writer can be made to wait for one batch, but not for the whole migration.

This matters because a single table-wide UPDATE holds row locks on everything it examines until it commits. One did: the event_objects.timestamp backfill held 71.9 million row locks for 31 minutes on a production cluster, and for all of that time every node's event writes failed with Lock wait timeout exceeded. Batching it trades a slightly longer migration for a cluster which keeps working through it. The progress of each batched backfill is logged by the command, as Backfill of <table>.<column>: N rows in M batches.

A migration which rewrites a large table is still the slowest part of an upgrade, so run sf-ctl ensure-mariadb-schema when you can afford to let it finish rather than interrupting it. If it does fail part way through, the table's schema version is not advanced and re-running the command resumes where it stopped.

A step which logs its failure and carries on, rather than stopping the run, also leaves its table's version where it was. The command then names each table it left short (Table '<table>' is at version N, short of version M) and exits non-zero instead of reporting the schema verified, because sf-database refuses to start on any table below the version the release expects. The network_interfaces version 4 step is one such: it adds the UNIQUE constraint which keeps an instance's interface device indexes distinct, and an ALTER TABLE on a serving cluster can lose a lock wait. Re-run the command once the warning it logged has been dealt with.

Not every migration costs that, and the cheap ones are kept cheap deliberately. Widening the columns which hold an object key, for example, is metadata-only: 63 characters of utf8mb4 is 252 bytes, under the 256 byte boundary where a VARCHAR's stored length prefix grows from one byte to two, so MariaDB accepts the change with ALGORITHM=INSTANT even on a column inside a primary key. A wider ceiling would have crossed that boundary and rebuilt every row of those tables under a metadata lock instead, which is why the ceiling is 63 and not something rounder.

Manual schema verification

You can manually check or apply schema migrations by running on a node with direct database access:

sudo /srv/shakenfist/venv/bin/sf-ctl ensure-mariadb-schema

This will output the current version of each table and whether any migrations were applied. For example:

Table 'object_states' is up to date (version 1)
MariaDB schema verified.

Or if a migration was needed:

Migrated table 'object_states' from version 1 to 2
MariaDB schema verified.

ENUM value reconciliation

Some columns (for example object_states.object_type) are native MariaDB ENUM types whose permitted values mirror a Python enum in the code. A MariaDB ENUM freezes its value list when the table is created, so a code upgrade that adds a new enum member leaves existing databases unable to store the new value — inserts fail with MariaDB error 1265 ("Data truncated for column ..."). Fresh installs are unaffected, which makes this failure mode easy to miss in greenfield testing; it is exactly what broke namespace key writes when the NAMESPACE_KEY object type shipped in July 2026.

To close this class of problem, sf-ctl ensure-mariadb-schema ends with a reconciliation pass that compares every native ENUM column against its Python enum and widens the column in place when the code has grown new values. Appending values to an ENUM is a metadata-only change in MariaDB and does not rewrite the table. Values removed from the code are deliberately retained in the column (existing rows may still hold them) and logged. The pass reports its work in the command output:

Widened ENUM column(s): object_states.object_type

or, on an up-to-date database:

Native ENUM columns are up to date

Because enum growth does not change any table version, this pass runs on every invocation rather than being version-gated. It is idempotent and cheap (one information_schema query per ENUM column).

Known migration notes

cluster_operation_targets v1 to v2

The v1 schema declared operation_uuid as a column-level UNIQUE, which prevented multi-target operations (e.g. the hot-plug interface op, which targets an instance, a network, and an interface) from recording more than one target row. The v2 migration replaces that constraint with a composite UNIQUE(operation_uuid, target_object_type, target_uuid) and adds a non-unique index idx_cot_operation for single-column lookups.

Operations already in flight at the moment the migration runs will have only their first declared target row in the table; their remaining target rows were silently dropped under v1 and cannot be reconstructed. The practical effect is that Network.is_okay()'s pending-operation gate may transiently miss one in-flight op per affected network during the upgrade window, and the network maintainer can race the queue worker once -- which manifests as the "Recreating not okay network on hypervisor" event firing in syslog for that network. The recreate is idempotent with the queued operation's own create_on_hypervisor, so there is no functional breakage; only the event.

Operations enqueued after the migration completes record all of their targets correctly, so the gate behaves as designed once the in-flight v1 ops drain.

cluster_operation_targets v2 to v3

The v3 migration adds an observational column (BOOLEAN NOT NULL DEFAULT 0) and widens the idx_cot_target index from (target_object_type, target_uuid) to (target_object_type, target_uuid, observational). The two "current state" readers (last_cluster_operation and the pending-operation check) will ignore observational rows. Three tasks are classified as observational (collect_billing_statistics, health_check_kvm_process and verify_size_and_checksum), so rows for those operations are marked observational and every other row is not. See when is a task observational for the rationale.

Run sf-ctl ensure-mariadb-schema before rolling the daemons. Only the database gateway (sf-database) checks schema versions at startup, via verify_schema_versions(); it refuses to start if cluster_operation_targets is below v3. Other daemons do not check, but they reach the table only through a gateway.

The migration is online. Adding the column is an instant metadata change, and the index is rebuilt in place over a small table, because finished operations are eligible for removal CLUSTER_OPERATION_RETENTION seconds after going terminal and are removed, with their target rows, by the deleted-object sweep. It took under half a second for 50,000 rows in testing. The migration is a single ALTER TABLE and is safe to re-run if interrupted: the re-run just rebuilds the index.

Older daemons still running during a rolling upgrade do not know about the column, so the rows they write take the default and are treated as mutating, which is how every row was treated before v3. The same holds in the other direction: a newer daemon whose enqueue reaches a gateway that predates v3 sends the flag, but that gateway drops it and writes the row as mutating. Nothing breaks, but a background sweep can still shadow last_cluster_operation until every gateway is upgraded, so roll the sf-database gateways before the other daemons.

The CreateClusterOperationTarget RPC has been removed, because the atomic enqueue already writes the target rows. An older node daemon that still makes the call during the roll gets an UNIMPLEMENTED error from an upgraded gateway and may log a failed CreateClusterOperationTarget call. This is expected and harmless: the row was already written by the enqueue, and the caller ignores the result.

namespace_attributes v2 to v3

The v3 migration drops the legacy keys JSON column. Namespace keys have been objects of their own in namespace_keys and namespace_key_attributes since the namespace_keys v2 migration, and nothing has read the column since — so what it held was a second copy of live bcrypt hashes and nonces at rest, which is an exposure with no benefit. The ALTER TABLE is a metadata-only drop on a table with one row per namespace, so it is quick, and DROP COLUMN IF EXISTS makes it safe to re-run.

sf-ctl ensure-mariadb-schema applies the namespace_keys v1 to v2 fan-out before this drop within the same run, so a cluster upgrading from a release that predates first-class keys copies its keys into the new tables before the column goes, no matter how many releases it skips. The fan-out proves its own copy: it records namespace_keys at version 2 only once every key in the column with both a hash and a nonce has a row in namespace_keys. If any does not, namespace_keys stays at version 1, the warning names the keys concerned, the drop refuses to run, the column and its keys stay in place, and a re-run retries the copy.

The drop trusts that version rather than copying again, on purpose. Once namespace_keys is at version 2 the cluster authenticates from it, so a key still in the column with no row there has either been removed since — removing a key is a hard delete, so a revoked key leaves nothing behind but its absence — or has not authenticated since the fan-out. Copying it back could only make a revoked credential valid again. A cluster which tracked development builds between the two migrations may therefore lose a key whose copy failed back then; that key has not worked since, and its owner needs a new one either way.

If the drop itself fails — a lock wait against a serving cluster, say — the table stays at version 2, the command names it as short of version 3 and exits non-zero, and sf-database refuses to start until a re-run succeeds: restarting it in between leaves the database tier down rather than bringing it back. That is deliberate: a step whose point is that key material stops being at rest must not report itself done while the column is still there.

Restart sf-database on every database node promptly after the command succeeds. A sf-database from the previous release still names the column in its queries, so until it is restarted onto this release every namespace attribute read and write it serves fails with an unknown column error. That covers more than namespace mutations: GET on a namespace, and the trust check that decides whether one namespace may use another's artifacts, fail too. Authentication is unaffected, because it reads namespace_keys, and keys are not lost in that window.

Rolling back across this migration is a credential event

While the column existed, rolling back to a release that predates first-class keys revived it, and every key that predated the earlier migration kept working. After v3 there is no column to revive, so such a release sees no keys for any namespace and POST /auth refuses every credential until keys are created again on the older release. If your rollback plan crosses this upgrade, take a database backup first, or plan to re-create namespace keys as part of it. Nothing is lost going forwards: this affects a downgrade only.

object_states v2 to v3

The v3 migration adds a standalone index idx_object_states_uuid on object_states(object_uuid). The table's primary key is composite, (object_type, object_uuid), so it cannot serve a join that keys on object_uuid alone. The in-flight-operation gate does exactly that — it joins cluster_operation_targets.operation_uuid to object_states.object_uuid without an object_type — so without the new index that join degraded to a full-table Block-Nested-Loop scan of object_states on every check. On a busy, long-lived cluster (tens of thousands of object_states rows) this produced a steady stream of Slow MariaDB query warnings and added latency to every operation gate, though no functional failure. The migration is a single online CREATE INDEX (MariaDB ALGORITHM=INPLACE), so it does not block writes and is quick even on a large table.

network_interfaces v2 to v3

The v3 migration adds an active column, fills it from object_states (TRUE for every interface which is not deleted, NULL for the ones which are), and replaces the global UNIQUE (macaddr) with UNIQUE (macaddr, active, network_uuid). The point of the NULL is that NULLs do not collide in a MariaDB unique index, so a soft-deleted interface keeps its row for audit without reserving its MAC until the deleted-object sweep reaps it.

That also means a constraint landed over a column the backfill did not fill would hold nothing at all, so a backfill which fails stops the step rather than logging and carrying on: the table stays at version 2 with the global UNIQUE (macaddr) it already had, which blocks MAC reuse for the length of the cleaner delay but is otherwise the behaviour of the release you are upgrading from. Re-run sf-ctl ensure-mariadb-schema to finish it; the backfill only looks at rows which are still NULL, so a re-run costs the rows the failed run did not reach and no more.

A cluster which ran an earlier form of this step has its interfaces marked active whether they were deleted or not, because the backfill's join never matched a state row. Nothing needs to be done about it: the affected rows are soft-deleted interfaces, each of which holds its MAC until the deleted-object sweep hard-deletes it, which is what the release before v3 did with every MAC anyway.

Database service architecture

Only the database node has direct access to MariaDB credentials. All other nodes access MariaDB data through a gRPC database microservice that runs on the database node. This means:

  • Schema migrations only need to run on the database node
  • Other nodes do not require MariaDB credentials
  • sf-ctl ensure-mariadb-schema must be run (or re-run after an upgrade) before starting sf-database
  • The database service must be running before other daemons can access state data

Rolling upgrade with drain

The procedure below achieves zero-downtime upgrades for the sf-api tier by exploiting the readiness drain built into every sf-api worker. It assumes you have a load balancer probing /readyz on port 13000 as described in Load Balancing. Without an LB watching /readyz, stopping sf-api is a hard cut rather than a graceful drain.

Before you start — schema migrations

If the release you are installing includes schema changes, you must apply them before rolling any nodes to the new build. Run the following on a node with direct MariaDB access (i.e. MARIADB_HOST configured — typically a database-tier node):

sudo /srv/shakenfist/venv/bin/sf-ctl ensure-mariadb-schema

sf-database refuses to start if the schema version does not match what its build expects, so applying migrations first lets you upgrade the database tier without downtime before touching the API or hypervisor nodes. If you roll a node before migrating, systemctl status sf-database names the refusal in its Status: line -- see the MariaDB compatibility requirements. See MariaDB schema migrations above and the database reference for full details.

Per-node procedure

Upgrade one node at a time. Confirm that each node is healthy before moving to the next.

1. Stop sf-api on the node.

sudo systemctl stop sf-api.socket sf-api

Stop the socket as well as the service. systemd, not gunicorn, holds sf-api's listening socket (sf-api.socket), and a connection to a stopped sf-api -- including your load balancer's next /readyz probe -- starts it again while its socket is open, which here would mean on a half-upgraded virtualenv. sf-api stops first and the socket closes after it.

Systemd sends SIGTERM. On receipt, the sf-api worker immediately flips /readyz to return 503 Service Unavailable. The load balancer detects this on its next health-check probe and stops sending new requests to this node. The worker keeps serving for the drain grace period (API_DRAIN_GRACE, default 25 s) and only then begins gunicorn's graceful shutdown. Note that gunicorn's --graceful-timeout countdown starts at the SIGTERM (not when the worker finally shuts down), so the two windows overlap rather than stack: with --graceful-timeout 55 s and a 25 s drain, in-flight requests have the remaining ~30 s to finish before gunicorn force-closes them. The systemd TimeoutStopSec of 70 s exceeds the graceful timeout and caps the whole sequence. For most workloads the node is out of rotation and quiet well within the grace period.

2. Upgrade the node's virtualenv.

Follow the manual venv-upgrade procedure described in Upgrade process above, for example:

sudo /srv/shakenfist/venv/bin/pip install --upgrade shakenfist

3. Restart SF services on the node.

For hypervisor nodes restart all services:

sudo systemctl restart sf-api sf-cleaner sf-cluster sf-net sf-nodelock \
    sf-privexec sf-queues sf-resources sf-sidechannel sf-transfers

For a database-tier node restart the database service first:

sudo systemctl restart sf-database
sudo systemctl restart sf-api sf-cleaner sf-cluster sf-net sf-nodelock \
    sf-privexec sf-queues sf-resources sf-sidechannel sf-transfers

Restarting sf-api also starts sf-api.socket again, because sf-api requires it.

Note

If the sf-cluster elected leader is on the node you are rolling, its cluster lock lease will expire (within 60 s of the daemon stopping). A standby node will then win the election and take over cluster maintenance automatically. See Locks for the lease and failover details.

4. Confirm the node is healthy before moving on.

Poll /readyz until it returns 200 OK:

curl -sf http://<node-ip>:13000/readyz && echo "ready"

/readyz returns 200 once the worker has successfully contacted sf-database. The load balancer will return the node to rotation on its next successful probe.

You can also probe the sf-database gRPC health endpoint directly:

grpc-health-probe -addr=<sf-database-host>:13005

SERVING means sf-database can reach MariaDB and the node is ready for the next node upgrade. See the database reference for details.

📝 Report an issue with this page