Deployment
- Introduction
- Building for production
- What goes on the server
- Environment configuration
- Running the server
- Running migrations
- Queue workers and the scheduler
- Deploying to DUST Cloud
Introduction
When you're ready to put your application in front of real users, you'll build it for production, give it a production environment, and keep its server, queue workers, and scheduler running. This guide walks through each step. If you'd rather not manage servers at all, skip ahead to DUST Cloud, the fastest way to ship and scale a dust-framework Rust application.
Deploying a dust-framework application is mostly moving files: one binary, the public directory, the views, and the storage directory. There is no language runtime to install on the server, no asset build step at boot, and no dependency tree to resolve in production. That makes a deploy fast and a rollback a matter of restoring the previous binary and its views.
Building for production
Your application compiles to a single binary, with your migrations built in. Build it in release mode:
dust build --releasedust build runs cargo build --release and copies the application binary and dust-cron into bin/. The output looks like this:
bin/
├── example-app
└── dust-cronDeploy from bin/, not from target/release/. Cargo's target directory holds intermediate artifacts that change between builds, while bin/ is the stable place the application's own commands and the cron daemon expect. A running binary can be replaced in place: the build writes a temporary file and renames it, so a deploy never leaves a half-written executable.
If you build with plain Cargo instead, build the daemon too and copy both binaries yourself:
cargo build --releasecp target/release/example-app target/release/dust-cron bin/Release builds take longer than development builds, but they run much faster and use less memory, so always deploy a release build. The io/ui assets are already in public/vendor/io-ui; there is no npm run build step.
What goes on the server
The binary holds your Rust code, but your application still reads a few directories while it runs. Put these next to the binary on your server, all under the application's base path:
| Path | Why it's needed |
|---|---|
bin/example-app, bin/dust-cron |
The server and the cron daemon. |
public/ |
The files your application serves directly, including public/vendor/io-ui. |
resources/views/ |
Your views and the root layout every page renders in. Read at runtime. |
config/ |
The TOML documents your application reads and writes, such as frontend.toml. |
storage/ |
Writable space for uploads, logs, the SQLite database, and the framework's working files. |
.env |
The production environment, if you keep it in a file instead of the process environment. |
Start the binary from your application's directory, the one that contains public/, resources/, and storage/. If your process manager starts it from somewhere else, set APP_BASE_PATH to your application's directory.
[!NOTE] A local
storage/directory belongs to one server, and many hosts erase it on every deploy. In production, keep uploads in DUST Cloud Object Storage or on an S3-compatible disk instead. If you use SQLite in production, put the database on a persistent volume, and run only one server against it.
Environment configuration
Your production environment needs its own settings, either in a .env file on the server or in your host's environment variables. Values in the process environment take precedence over .env, so a secret manager that exports variables works without a file. At a minimum, set these:
APP_ENV=production
APP_DEBUG=false
APP_KEY=base64:...
APP_URL=https://example.com
DATABASE_URL=postgres://app:secret@db.internal/example| Variable | What it does |
|---|---|
APP_ENV |
Names the environment. Set it to production. |
APP_DEBUG |
Shows detailed error pages and reloads views. Set it to false. |
APP_KEY |
Encrypts cookies and sessions. Generate a different key than your machine's. |
APP_URL |
The public origin. Used for absolute URLs, signed URLs, and the trusted host check. |
DATABASE_URL |
The production database. See the database guide. |
Use a different key in production than on your machine. On DUST Cloud, each environment gets its own key automatically. On your own servers, generate one with:
./bin/example-app key:generate --showCopy the value into APP_KEY, then restart the application. Changing the key invalidates existing cookies and sessions, so rotate it with care; the encryption guide covers a graceful rotation. As your application grows, the configuration guide shows you how to add settings of your own and read them anywhere in your code.
[!WARNING] Always set
APP_DEBUGtofalsein production. With debug mode on, server errors render a page with the error, its causes, the route, and the request, for anyone to see.
Running the server
Run the binary with no arguments to serve your application:
./bin/example-appThe server listens on 127.0.0.1:8000 by default. In a container, or anywhere the server must accept connections from other machines, listen on every interface instead:
SERVER_HOST=0.0.0.0
SERVER_PORT=8000Keep the default loopback binding when a reverse proxy runs on the same machine: only the proxy can reach the application, and the proxy handles TLS. Run the server under a process manager, such as systemd or your container platform, so it starts with the machine and restarts if it stops. To deploy a new version, replace the binary and restart the process.
Rust binaries don't need a runtime, but they do need the same shared libraries you built against or a statically linked C library. Build on the same architecture and libc as the server, or build in a container that matches it. A binary built on macOS won't run on Linux.
Stopping gracefully
When your process manager stops the previous server with SIGTERM (or when you press Ctrl+C), dust-framework stops accepting new connections and gives in-flight requests time to finish. SERVER_SHUTDOWN_TIMEOUT controls how long the server waits, defaulting to 20 seconds. Any request still running when the timeout expires receives a 503 response. Keep this value shorter than your process manager's kill grace period so the server exits cleanly before being terminated.
SERVER_SHUTDOWN_TIMEOUT=15During shutdown, event streams close immediately so browsers reconnect to the new instance. Ticks stop scheduling new runs, and any tick marked run_on_shutdown executes one final time after active requests and background work finish.
A graceful stop is what makes a rolling deploy invisible: the new process starts, the load balancer sends it new requests, and the old process finishes the requests it already accepted. If your process manager starts and stops both at once, or drains too quickly, users see 503s during the swap.
Behind a load balancer
Most production servers sit behind a load balancer that handles HTTPS. Tell dust-framework to trust it, so request.ip() returns the client's address and the URLs your application generates start with https://:
// src/app.rs.with_middleware(|middleware, _| { middleware.trust_proxies(["10.0.0.0/8"]);})Not sure what to put in that list? The trusting proxies section of the middleware guide helps you find your load balancer's addresses, and explains when it's safe to trust every proxy instead.
Health checks
Load balancers and uptime monitors often need a way to tell whether your application is running. A new application answers at /health, and you may register the framework's health check at another path with routing.health(...):
// src/app.rs.with_routing(|routing, _| { routing .web(routes::web::routes) .health("/up");})Both respond with a 200 once your application has started. Point your load balancer's health check at whichever path you keep. If the path clashes with one of your routes, or your load balancer expects another path, the routing guide shows you how to change it.
Limiting connections
By default, dust-framework accepts up to 8,192 concurrent TCP connections (including idle keep-alive connections and open event streams) so a sudden traffic spike or flood of slow clients can't exhaust your server's memory. Once the server reaches that limit, new connections wait until an open one closes.
The default works well for most applications, though you may adjust it with the SERVER_MAX_CONNECTIONS environment variable:
SERVER_MAX_CONNECTIONS=2048Lower the limit on memory-constrained servers, such as a 512 MB container, or raise it if your application holds thousands of long-lived connections open at once. You may also set SERVER_MAX_CONNECTIONS=0 to disable the limit.
A systemd unit
A small systemd unit keeps the server running and restarts it after a crash or a reboot. Save this as /etc/systemd/system/example-app.service:
[Unit]
Description=example-app
After=network.target
[Service]
Type=simple
User=www-data
Group=www-data
WorkingDirectory=/srv/example-app
EnvironmentFile=/srv/example-app/.env
ExecStart=/srv/example-app/bin/example-app
Restart=always
RestartSec=1
KillSignal=SIGTERM
TimeoutStopSec=25
[Install]
WantedBy=multi-user.targetWorkingDirectory is what lets the application find public/, resources/, and storage/ without setting APP_BASE_PATH. TimeoutStopSec must be longer than SERVER_SHUTDOWN_TIMEOUT, so systemd gives the server time to drain before it sends SIGKILL.
Reload systemd after you add or change the unit, then start it:
sudo systemctl daemon-reloadsudo systemctl enable --now example-appTo deploy, replace bin/example-app and the views, then restart:
sudo systemctl restart example-appThe full command map for dust install, dust build, dust status, and dust restart is in the commands guide.
Running migrations
Run your migrations as part of each deploy, before the new version starts serving requests. In production, migrate asks you to confirm before it runs, so pass --force in a deploy script:
./bin/example-app migrate --forceIf you deploy to several servers, run migrate from only one of them. On DUST Cloud, you don't need to arrange this yourself: put example-app migrate --force in your deploy commands, and Cloud runs them once for each deploy, however many instances you have.
Migrations are forward-only: a deploy that changes a column needs the old and new code to agree on the schema while both run. Add a column before the code that writes it, and remove a column only after no running instance reads it. The migrations guide covers how to write a change that both versions can live with.
Queue workers and the scheduler
If your application dispatches queued jobs, run at least one queue worker under your process manager, next to the server:
./bin/example-app queue:workA worker runs the code it was compiled with, so restart your workers on every deploy, just as you restart the server. Run them in their own systemd unit, with the same WorkingDirectory and environment as the server, so a crash in a worker doesn't take the web process with it.
If your application has scheduled tasks, you have two options:
- The cron daemon.
dust installadds the coreschedule:runcron and startsdust-cron, which runs it every minute from its own process. This is the default for a new application, anddust restartrestarts the daemon. - System cron. Add one entry that runs the scheduler every minute, if you don't use the daemon:
* * * * * cd /path/to/example-app && ./bin/example-app schedule:run >> /dev/null 2>&1Do not enable both. Two schedulers running the same tasks double every job they dispatch. If you move from one to the other, stop the daemon or remove the cron entry first.
If your schedule has sub-minute tasks, run schedule:interrupt once the new build is in place, so a schedule:run that's already repeating them stops instead of running your previous build until the end of the minute:
./bin/example-app schedule:interruptDeploying to DUST Cloud
DUST Cloud is a fully managed platform from the team behind dust-framework, and it's the best way to ship and scale your dust-framework Rust application. Push to Git, and Cloud builds your application, runs your migrations, and rolls out the new version with no downtime.
Cloud takes care of the parts of production that are hardest to get right:
- Autoscaling that follows your traffic, and scale-to-zero when your application is idle, so you only pay for what you use
- Preview environments for every pull request
- Managed MySQL and Postgres databases, and Valkey caches
- Managed queues whose workers scale with the jobs waiting
- A built-in scheduler that runs your scheduled tasks, waking your application on time even when it has scaled to zero
- Object storage for your application's files
- Managed WebSocket servers
- HTTPS, a global edge network, logs, and metrics, with nothing to configure
dust-framework already knows how to run on Cloud. When your application starts there, it listens on the address and port Cloud gives it, with no SERVER_HOST or SERVER_PORT to set, and each environment gets its own APP_KEY. When you create your Cloud environment, add your build and deploy commands:
# Build commandscargo build --release# Deploy commandsexample-app migrate --forceCloud runs your binary to serve your application. For queued jobs, enable the sqs feature and set QUEUE_CONNECTION=cloud to use Cloud's managed queues. For broadcasting, use Cloud's managed Relay instead of running the local relay:start server in production.
Application logs, scheduled command output, and reported server errors stream to Cloud's Logs page automatically.
Cloud runs your scheduled tasks too, with no cron entry to manage. Enable the Scheduler toggle on your environment's App cluster, as Cloud's scheduled tasks guide shows, and Cloud runs schedule:run every minute. When your environment runs several instances, mark tasks that should run only once with on_one_runner, and set CACHE_STORE to a store every instance shares, such as database.
To deploy your first application, get started with DUST Cloud.