Server Rollouts
A server rollout takes a server, puts one of the platform's things on it, and hears back from the server that it is ready. It is one piece in core that every feature putting something on a server uses, so a new provider or a new thing to put on a server is added in one place.
A rollout joins two halves:
- A target: where it goes.
madeis a server this site creates at a cloud provider, through that provider's driver (ComputeDriverRegistry).broughtis a server the owner already has, at any provider, set up by one command (below). - A payload: what goes on it. A class implementing
RolloutPayload, registered by key: core's management node (management_node, deployed from a site's Management Node page), the mailbox plugin's mail relay (relay) and relay fleet shard (relay_shard), and Server Manager's site (site: every server a management node makes for a site, a bare host or a copy).
ServerRolloutView::broughtBox(), naming the actions its own handler takes.A payload never asks which kind of target it is on, and the target never asks what it carries.
How a run goes
Nothing logs in to the server. It is created with a first-boot script, builds itself, and reports back over HTTPS with a one-time token.
| Status | What is happening |
|---|---|
awaiting_grant | Opened; waiting for a provider credential for this one act |
waiting | A brought server: the command is shown; no server has called yet |
confirming | A brought server: a server has called with the code; waiting for the owner to confirm it |
ready | A credential is held; nothing created yet |
creating | One worker has claimed the run (claimForCreate()) and is creating the server |
draining | An update: waiting for the payload to allow the re-image (beforeRebuild()) |
rebuilding | An update: cleared for the re-image |
reimaging | An update: one worker has claimed the re-image and is asking the provider for it, keeping the server's address |
booting | Waiting for the server to run with a public address |
provisioning | The server is building itself; waiting for its report |
switching | An update by swap: the new server is believed; emptying the old one and swapping their addresses |
handing_over | An update by name move: the feature runs on the new server; waiting for the old one to be let go |
done / failed | Ended. Both erase every credential the run holds and its file copies |
ServerRolloutRunner::advance() moves a run one step. The core task Advance server rollouts
(tasks/AdvanceServerRollouts.php) calls it for every live run on every cron pass.
advanceCheap() takes only the one-call steps (create, re-image, boot poll) and is safe inside a
page load, so a run moves while its owner watches.Every status move is a conditional update (ServerRollout::moveStatus(), failIfLive()), and each
advance starts from the row as it is now, so a worker holding an older copy never undoes another
worker's move or the server's own report. Timeouts are measured from sro_status_time, which only
a status move stamps.
A run that fails deletes the server it created only when the payload's deleteOnFailure() says
so. An update deletes only the new server it made, and only before its switch-over begins. A provider's 4xx (but 429) ends the run. A 5xx or a network failure
before anything was asked of the provider is tried again on the next pass. After a create or a
re-image was asked, a lost answer does not prove nothing happened: the run waits in its claim
(creating, reimaging) and, after 15 minutes, fails naming the server's label to look for, rather
than asking again and making a second server.
The run's credentials
ServerRollout (data/server_rollouts_class.php, table sro_server_rollouts) holds, sealed with
SecretBox and only while the run is live:
sro_sealed_token: a provider token pasted for this one act. A run may instead name an account Server Manager keeps (sro_cloud_account_id); the runner then asks that account for a driver at each step and no token is copied onto the run, and stops with the account's own reason when it can no longer be used.
minimumMemoryMb() asks for.
sro_sealed_run_token: the one-time token the first-boot script presents. It expires after the boot window plus the payload's report window, and the report spends it.sro_sealed_secret: the one value the server fetches once (a first admin password), set by the payload withsealSecret().
sro_fields (JSON). No secret goes there.The calls a new server makes
ServerRolloutEndpoint, routed from api/apiv1.php before key authentication. The token travels in
the X-Joinery-Rollout-Token header, never on a URL. Metered in its own api_rollout bucket.
| Call | What it does |
|---|---|
GET /api/v1/rollout/script?payload=KEY | The fixed script a brought server runs for a payload: this site's address and the payload written in, nothing of any run |
POST /api/v1/rollout/hello | A brought server calling with its code: {code, match[, link]} |
GET /api/v1/rollout/bundle?run=ID&sha256=HEX | The run's own copy of the support bundle, when the payload asked for one, by the hash its script carries |
GET /api/v1/rollout/agent?run=ID&sha256=HEX | The run's agent kit, the same way |
GET /api/v1/rollout/secret?run=ID | The one-time value, handed over once and erased; only to a call from the server's own address |
POST /api/v1/rollout/born | The report: {"report": {"run_id", "public_ip", ...}, "signature": "..."} |
POST /api/v1/rollout/failed | {"run_id", "log"}: the script stopped; the run keeps up to the last 16384 characters of its log and fails. The script sends no more than that (tail -c 16384) |
verifyReport() passes. The report then claims the token, so of two reports at once
only one goes on, and the payload's complete() writes what its feature keeps; the run is done. A
run whose report is being completed is not timed out. A payload's refusal (RolloutRefused) answers 409 and leaves the run as it
was, so the server's next report gets another go.A server the owner brings
A brought run asks no provider for anything and holds no provider credential. The page shows one
command, the same for everyone who uses this payload:
bash -c "$(curl -fsS 'https://<site>/api/v1/rollout/script?payload=<key>')"and a code: the run's id and its one-time token (ServerRollout::code()), live for two hours.
The script (includes/server_rollout/brought_server.sh) checks the machine (Ubuntu 26.04, no Joinery
site, relay or agent on it), prints the payload's beforeCommandNotice(), which the owner already
ticked on the page, and asks for the code at a prompt, so the code is never on a command line. It
makes a short code of its own (4F7K-2Q), prints it, and calls hello every ten seconds, over
IPv4 and IPv6 in turn, so the page can list it by either address. Only a refusal ends the wait; a
network failure, a busy site or a server error is asked again. hello has its own rate-limit bucket
(api_rollout_hello), so waiting never spends what the build then needs.
- Until the owner confirms a server, every caller is noted on the run (
sro_seen_addresses: its address and the short code it shows, the newest few kept, an IPv6 caller by its /64) and told to wait. A code holder sharing the owner's /64 (some providers hand single addresses to different customers from one) can replace that row between polls; the owner then sees a short code that is not the one on their terminal and confirms the IPv4 row instead. It is handed nothing: the bundle, the agent kit, the secret and the report are refused to a brought run's unconfirmed callers. - The page lists each caller with its short code. This is mine (
confirmServer()) makes its address the run's; the run moves toprovisioning, and only calls from that address are believed. Not mine (refuseServer()) ends the code and fails the run. Show a new command (openCommand()) ends the old code and starts again. - The confirmed server's next
hellois handed the payload's first-boot script, rendered with the run's token (broughtScript()), and a value it presents over its other address family to link that address too (sro_link_value). The code then lives for the payload's report window from the confirmation, wherever in its two hours that came. - The script runs the payload's script in the background (
systemd-run, unitjoinery-rollout-<payload>), since a payload may end the session that started it, and follows its log. - The page also offers the same script with the code filled in, for a provider's "user data" box; it prints its short code to the server's console.
acceptsBroughtServer() returning true (a relay does, a fleet shard does not).Nothing on a brought server is ever deleted or powered off. A code nobody runs ends after two
hours; a confirmed server that does not report within the payload's window fails the run, which
says to re-image it before trying again. An update of a brought server (sro_update_path rerun)
runs the payload's beforeRebuild(), then shows a new command: the owner re-images the server at
their provider and runs it.
Writing a payload
Implement RolloutPayload (includes/server_rollout/RolloutPayload.php):
| Method | Answers |
|---|---|
key(), label() | The registry key and what the owner calls it |
firstBoot($run) | ['template' => path, 'fields' => [NAME => value], 'bundle' => bool] |
verifyReport($run, $report, $signature) | Is the report to be believed, beyond the token and address? Throws RolloutRefused |
complete($run, $report) | Write what the feature keeps. Throws RolloutRefused to wait for a retry |
beforeRebuild($run) | An update may re-image: '' goes ahead, a reason waits a pass, RolloutRefused fails it |
minimumMemoryMb() | The smallest machine it runs on |
deleteOnFailure() | May a failed run delete the server it created |
reportTimeoutSeconds() | How long the server has from boot to its report |
beforeCommandNotice() | What the owner must be told and tick before a brought server's command; '' for none |
addressName($run) | The public name that must point at the server; '' for none |
handOver($run, $old) | An update by name move: '' once the old server may be deleted, else what it waits for |
RolloutPayloadRegistry::CORE; a plugin's goes in its
plugin.json, and resolves only while the plugin is active:"rolloutPayloads": { "relay": "RelayRolloutPayload" }A run whose payload this site no longer has fails on its next pass and deletes nothing.
Two optional methods. acceptsBroughtServer(): bool offers a brought server's command for the
payload (below). driver($run): CloudComputeProvider says the payload's own feature makes the
server, with a credential only it holds: the runner asks it for the driver before the run's own
account or token. Such a feature creates (or re-images) the server itself, in its own account:
it opens the run in awaiting_grant, asks `ServerRolloutRunner::firstBootOptionsFor($run,
$driver, $region)` for the options that carry the run's first boot, adds them to its own create or
rebuild call, and hands the server back with attachServer($run, $instance), which moves the run
to booting. From there the run goes as any other. Server Manager's site payload works this
way: a site's provision decides the account, the encryption rule and the root password, and the
runner polls the boot, keeps the report window and takes the report.
The first-boot template
The template writes each field as
GREETING="${GREETING:-__GREETING__}"so one template serves both ways a provider hands a script over (FirstBootScript): rendered, with
every value written in, as cloud-init user data; or with the placeholders kept under a header
declaring each field, the values arriving as environment variables. A field with no value is empty
in both. Every value must be free of quotes, $, backticks, backslashes, newlines and }; one that
is not is refused and nothing is created.
The runner adds PLANE (this site's https address), RUN_ID and RUN_TOKEN, and BUNDLE_SHA256
and AGENT_SHA256 when the payload asked for the bundle. A payload may not set those names.
The script stores the token in a root-only file, sends it in the X-Joinery-Rollout-Token header,
and erases what it fetched before it exits.
Adding a provider
A driver implementing CloudComputeProvider and CloudInstanceTypes (the image a server is
installed from is defaultImage()), listed in ComputeDriverRegistry::DRIVERS, can host a made
target. A driver whose provider has more than one way to hand over a first-boot script implements
CloudFirstBootScript; Linode's sends user data where the region has its Metadata service and a
private StackScript per template where not. Any other driver is given the rendered script as
user_data.
A driver whose provider can keep a server's addresses when the server is deleted implements
CloudAddressCarryOver (Hetzner's primary IPs): keepAddresses() keeps them and returns their
ids, createInstance() takes those ids as kept_addresses and gives them to the new server, and
letGoOfAddresses() undoes a keep. A site's Retry Install that has to replace its server uses it, so
the site's address and every DNS record naming it stay as they were.
Updating a server
Every provider gets a working update. The runner takes the first path the driver allows, once, and
records it (sro_update_path):
- Re-image in place (
reimage), when the driver implementsCloudRebuildFirstBoot: itsrebuildInstance()keeps the server's address and runs the first-boot options it is handed (Linode's does). The payload'sbeforeRebuild()runs first; the server is re-imaged with a fresh script and run token. - Replace, then swap the addresses (
swap), when the driver implementsCloudAddressSwap(Hetzner's does; its rebuild installs the image alone and refuses first-boot options). A new server is created beside the old one, in its region. Its report is verified and held (sro_report), and each pass then takes one step (sro_switch_step): the payload'sbeforeRebuild()on the old server, both powered off when the driver isCloudSwapWhileStopped, the two IPv4 addresses swapped, both powered on (or rebooted), and once both run, the new one at the old address, the payload'scomplete()with that address (asked again next pass while it refuses). The payload'shandOver()is then asked about the old server at its new address (a relay collects what it took after its drain), and the old server is deleted. Where the driver keeps moved addresses (CloudAddressRelease), both go with their servers again, before any server is deleted: the old server's final one at once, and the one the new server took over whenever that server is deleted. The same release runs when a switch-over fails, so a server the owner later deletes by hand takes its address with it. The switch-over has an hour. A failure before the addresses change hands puts each address back on its own server, boots the old server again and deletes the new one; after, both are booted, kept and named. - Replace, then move the name (
rename), at any other provider, when the payload names one (addressName()). The new server keeps its own address; its report completes the payload at once, and each pass asks the payload'shandOver()until it lets the old server go, which is then deleted. While it waits,ServerRollout::nameMovePlan()is the change to publish: the name's A record at the new server, and its AAAA record at the new server's IPv6 address (or removed, when the new server has none) where the name answers one. A page hands that plan to the shared DNS publish box (DnsPublishBox, see DNS Management), so a zone at a host with a driver is changed from the page.
sro_replaces_*). Before the switch-over a failure deletes only the
new server, when the payload allows; from the switch-over on nothing is deleted, and the run says
which server holds what. Releasing an address and deleting the old server are each tried again on a
transient failure; a refusal ends the run done, naming the server still to delete or the address
still kept at the provider.Tests
tests/server_rollout/server_rollout_test.php drives the runner and the endpoint with a test
payload against a fake provider registered through ComputeDriverRegistry::$factories.