Overview
A Stalwart 0.15 or 0.16 server has no connector in vandelay migrate: detection recognises it, but it cannot be selected as a source. Its accounts are moved by hand instead, with the same zero-downtime design that vandelay migrate follows for other self-hosted servers. The two servers run side by side behind the Stalwart proxy, and the accounts move one at a time, copied with the per-account Vandelay commands. Throughout these pages, the existing server is called the source, and the new Stalwart server the new deployment.
Use cases
Section titled “Use cases”A Stalwart 0.16 deployment can also be moved as a whole with stalwart-migrate, as described in Upgrading from 0.16. That tool copies the entire deployment, settings and data, into a new 1.0 store while 0.16 keeps serving users, and the deployment is down only for its final run. It suits small and medium deployments that can hold a second copy of their data store.
The account-by-account procedure on these pages suits the other cases:
- A Stalwart 0.15 source, or a 0.16 deployment that cannot hold a second copy of its data store
- A migration that must not interrupt service beyond a single restart of the source
- A move to new hardware or another storage backend, one account at a time
- The consolidation of several servers into one
It is also the procedure for a target that vandelay migrate does not support, because the per-account commands write to any JMAP server.
Migration process
Section titled “Migration process”The migration follows the topology of a zero-downtime migration. The proxy routes each client session by the account in its credentials: an account without a mapping goes to the source, and a moved account has a mapping to the new deployment. Inbound SMTP has no login, so the proxy passes port 25 to the new deployment, which delivers mail for moved accounts and relays the rest to the source. The MX records never change during the migration.
What vandelay migrate automates for other sources is done here by hand. The domains, DKIM keys and accounts are created on the new deployment with stalwart-cli, each account is copied with vandelay import jmap, vandelay import webdav and vandelay export, and its mapping is switched through the proxy’s management API. The source is never written to, so a moved account can be routed back to it until it is decommissioned, as described in Rollback.
Prerequisites
Section titled “Prerequisites”The migration requires:
- A host for the new Stalwart deployment, separate from the source
- A host for the proxy, which takes over the public server name and ports of the source
- Access to the DNS records of the public server name and of the migrated domains
- The possibility to restart the source once, during a maintenance window
- A host for Vandelay with access to both servers, and enough free disk space for the archives kept at the same time
- Administrator credentials for the source and the new deployment
- A test account on the source, to check each stage before real accounts depend on it
The migration has seven steps. Only the fifth interrupts service, briefly:
- Install the components. Install the new deployment,
stalwart-cli, the proxy and Vandelay. Nothing serves clients yet. - Prepare the new deployment. Create the domains, prepare keys, certificates and DNS, and apply the settings for the proxy, as described in New deployment.
- Configure the proxy, with two destinations,
oldfor the source andnewfor the new deployment, and HTTP routing for two Stalwart servers, as Migrating between Stalwart servers shows. - Prepare the source. Stage the settings that let the source accept the proxy and the mail relayed from the new deployment, as described in Source settings.
- Go live. Apply the source’s settings, restart it, start the proxy and repoint the public server name, as described in Going live.
- Move the accounts, one at a time, as described in Moving accounts.
- Finish. Let the new deployment answer clients directly, remove the migration settings and decommission the source, as described in Finishing.
The troubleshooting page lists the problems specific to a Stalwart source.
Checks on the source
Section titled “Checks on the source”Three properties of a Stalwart source decide how its accounts are copied and routed: the data types it serves over JMAP, the form of its logins, and its HTTP routes. Check them on the source before preparing it.
The first property is visible in the JMAP session of the source. Fetch it with the credentials of any account on the source; Stalwart answers /.well-known/jmap with a redirect to /jmap/session on the same host, which -L follows:
The capabilities object of the response names the capabilities the source advertises, and the accountCapabilities of each account those it offers for that account. Vandelay copies a data type over JMAP only when the account offers the matching capability:
| Capability | Data types |
|---|---|
urn:ietf:params:jmap:mail | Mailboxes and email |
urn:ietf:params:jmap:submission | Identities |
urn:ietf:params:jmap:sieve | Sieve scripts |
urn:ietf:params:jmap:contacts | Address books and contacts |
urn:ietf:params:jmap:calendars | Calendars and events |
urn:ietf:params:jmap:filenode | Files |
When a capability is missing, its data type is copied with the matching protocol importer instead: files with the WebDAV importer, contacts with the CardDAV importer and calendars with the CalDAV importer. Files are always copied over WebDAV, because Stalwart 0.15 and 0.16 advertise urn:ietf:params:jmap:filenode but implement an earlier draft of JMAP file storage. Selecting an account by a name that the administrator’s session does not list also requires urn:ietf:params:jmap:principals; without it, the account is selected by its JMAP account identifier. An account found this way is not listed in the session, so Vandelay cannot check its capabilities and attempts every data type it is given.
The second property, the login form, decides which mapping entries the proxy needs. A source on which users sign in with a bare name, such as alice, needs a mapping entry for the bare name and one for the address once the account moves, and calendar and contact clients configured with a bare-name collection URL are updated after the move, as described in Login names after migration.
The third property is the HTTP routes. Because both servers are Stalwart servers, their HTTP routes overlap. A route that exists on both cannot be routed by its path, so the proxy routes such requests by the account they identify, and sends requests that identify no account to a default destination, as the proxy example describes.
New deployment
Section titled “New deployment”The new deployment receives the accounts as they move, and from the moment the proxy goes live it is the public mail exchanger of the migrated domains. It serves no clients yet, so preparing it causes no downtime. The examples use stalwart-cli, with the new deployment’s address and an administrator’s credentials in STALWART_URL, STALWART_USER and STALWART_PASSWORD; every object can also be edited in the WebUI.
Every domain of the source must exist before any of its accounts can move, and before split delivery can recognise the domain as local. Create each Domain, found under Management › Domains › Domains, by name; the setup wizard already created the default domain:
stalwart-cli create Domain --field name=example.orgThen prepare the rest, most of which is shared with every zero-downtime migration:
- Proxy trust, public URL, split delivery and bare login names, as described in Stalwart settings. Nothing creates the domains’ relay settings for this procedure, so all of them are set by hand.
- DKIM keys, imported from the source or generated under new selectors and published next to the old ones, as described in DKIM.
- Certificates and DNS, as listed in Certificates and DNS.
- Limits for the bulk import. Raise the limits listed in Stalwart limits, and exempt the Vandelay host from automatic banning with an AllowedIp entry, found under Settings › Security › Allowed IPs, which
vandelay migratewould otherwise create:stalwart-cli create AllowedIp --field address=203.0.113.40 --field reason="Vandelay host".
When the source’s outbound mail is to leave through the new deployment, an optional step described in Source settings, the new deployment must also relay for the source. With its default allowRelaying expression of MtaStageRcpt, found under Settings › MTA › Session › RCPT TO Stage, it relays to remote domains only for authenticated sessions, and rejects the source with 550 5.7.1 Relay not allowed. The following value keeps the default for every other client and adds the source, here at 203.0.113.30:
{ "allowRelaying": { "match": { "0": {"if": "remote_ip == '203.0.113.30'", "then": "true"} }, "else": "!is_empty(authenticated_as)" }}With the value saved as relay.json, apply it with stalwart-cli update MtaStageRcpt --file relay.json. Mail relayed this way arrives unauthenticated, so the new deployment does not sign it with DKIM under the default dkimSignDomain expression; the source keeps signing its own mail.
Going live
Section titled “Going live”A source prepared as described in Source settings changes its behaviour as soon as it restarts: its listeners then expect a PROXY header on every connection from the proxy’s network. Perform the following actions in close succession:
- On a Stalwart 0.16 source, run the commands that disable the inbound authentication checks and the EHLO requirement, and the routing command when outbound mail goes through the new deployment. Add
STALWART_INCLUDE_SECRETS=1to the environment of the service, together withSTALWART_PUBLIC_URLwhen the source needs it. A Stalwart 0.15 source already holds these settings. - Restart the source, so that the listener settings take effect together with the others. A reload is not enough for the listener settings.
- Restart the proxy, so that it reads its configuration. It binds the public ports and resolves every account to the source, because no account has a mapping yet.
- Repoint the public server name to the proxy, by changing its DNS records or by moving the public address to the proxy host. Clients that still resolve the old address reach the source directly and are served, but bypass the proxy’s routing until their cached record expires.
Then test each protocol through the proxy with the test account, which is still on the source, and send a message from outside to an account on the source to confirm that it arrives through the new deployment’s relay. After this step, every account is still served by the source, from the same server name, and the accounts can be moved at any pace.
Finishing
Section titled “Finishing”When every account has moved and been validated, follow Finishing to confirm that nothing still depends on the source, repoint the public server name to the new deployment and remove the migration settings: the relay route and routing rule, allowRelaying, the proxy’s trusted network, and the limits raised for the bulk import. This procedure has no Vandelay Finish operation, so the rest is done by hand as well:
- Create the catch-all addresses that were held back to keep split delivery working.
- Delete the AllowedIp entry of the Vandelay host, and remove the source’s address from the relay rule of MtaStageRcpt if it was added.
- Delete the archives once their accounts are validated, because they hold the accounts’ data.
- On a Stalwart 0.16 source that stays in service for another purpose, remove
STALWART_INCLUDE_SECRETSfrom its environment and restart it, because while it is set every caller allowed to read an account receives its password hashes.
The proxy’s mapping entries for the administrator and for the web clients’ OAuth client identifiers disappear with the proxy. Shut the source down only after a period of confidence that the new deployment works on its own: until then, it holds a copy of every account as it stood when that account moved.
Downtime
Section titled “Downtime”Steps 1 to 4 cause no downtime, because they do not change the path that clients take to the source; the settings staged on the source take effect only when it restarts. Going live is the one short interruption, for as long as the source takes to restart, plus the time some clients take to follow the DNS change, which is why the TTL of the public server name is lowered a day in advance.
Moving an account causes no downtime. When its mapping changes, its open sessions are closed, and clients reconnect to the new deployment. They then see the account’s data as new data, because the new deployment assigns its own identifiers: IMAP clients download the folders again, CalDAV, CardDAV and WebDAV clients synchronise their collections again, and a saved link to a single event, contact or file on the source no longer resolves. Every message also carries one of the keywords $hasattachment and $hasnoattachment, which Stalwart sets from the message’s content.
Items not carried over
Section titled “Items not carried over”Vandelay copies an account’s data: its mailboxes and messages, identities, Sieve scripts and vacation response, address books and contacts, calendars and events, and files. The rest is carried as follows, or not at all:
- Passwords and account properties. The account plan scripts described in Create the account on the new deployment recreate each account with its password hashes, description and aliases, and on Stalwart 0.16 with its quotas and two-factor authentication secret. App passwords and API keys are not carried, so users create their app passwords again.
- Groups and mailing lists, which are recreated on the new deployment by hand, or with the scripts’
--include-groupsoption. - Sharing. Access rights granted to other accounts on mailboxes, calendars, address books and files are granted again after both accounts have moved.
- Participant identities, which the new deployment creates from the account’s addresses the first time they are read. A user who scheduled under another name or a subset of addresses adjusts them after the move.
- Server settings and server-wide Sieve scripts. Only the scripts that belong to an account are copied. A source script named
managed, the name the new deployment reserves for the script that holds its vacation response and mail rules, is exported under a new name, and the export’s warning names both. - Client authorisations. Push subscriptions, OAuth grants and WebUI sessions are tied to the server that issued them, so clients that use OAuth sign in again after their account moves.