Deployment
Operations
- Logs:
journalctl -u myapp(-ffollows,--since "1 hour ago"); withLOG_FILE, alsostorage/logs/smeltery.logand its.1backup. Requests are logged atdebug; secrets in URLs appear as[redacted]. - Health checks: point an uptime monitor or load balancer at
https://app.example.com/up(200, bodyOK). -
Backups:
.env(without itsAPP_KEYevery session, signed Spark state and the API token change), the database andstorage/app/. Backups hold password hashes and sessions, so they go into a folder only root can read:sudo install -d -m 700 /var/backups/myapp # SQLite (apt install sqlite3): a consistent copy while the app runs sudo sqlite3 /srv/myapp/database/database.sqlite ".backup '/var/backups/myapp/db.sqlite'" # PostgreSQL sudo -u postgres pg_dump -Fc myapp | sudo tee /var/backups/myapp/myapp.dump > /dev/null # MySQL (root signs in through the socket on Ubuntu) sudo mysqldump --single-transaction myapp | sudo tee /var/backups/myapp/myapp.sql > /dev/nullCopying the SQLite file alone misses what is still in
database.sqlite-wal;.backupincludes it. WithQUEUE_DRIVER=redisthe queued jobs and dead letters are on the Redis server, kept by its own persistence (RDB or AOF). - RotatingAPP_KEY(a new key fromkey:generate --showas under "Production.env", pasted into.env, then a restart) signs every user out (session and remember-me cookies), invalidates the Spark state in open pages and pending signed uploads, and changes the Watchfire API token. Database rows stay as they are. - Clearing the cache:sudo -u myapp ./myapp cache:clearkeeps Watchfire's leases and schedule claims.cache:clear --allremoves them too: the processes take their agents again withinWATCHFIRE_LEASE_TTL, and until then a singleton agent can run in two processes and a tick of the current minute can run again. - Sharing a cache store: Watchfire's leases and schedule claims, the cache entries and locks of the app all live underCACHE_PREFIX(default<app name>_cache_). Two apps, or the staging and production copy of one app, on one Redis database, memcached server or database need differentCACHE_PREFIXvalues (or separate Redis databases or tables); with the same prefix they take each other's leases and claims and read each other's entries. Memcached cannot flush by prefix, so a shared memcached is emptied for every app bycache:clear --all. - Sharing a Redis queue: withQUEUE_DRIVER=redis, two apps (or the staging and production copy of one app) on one Redis database need differentQUEUE_PREFIXvalues (default<app name>_queue_) or separate Redis databases; with the same prefix their workers take each other's jobs. - HTTP caches: web pages are per visitor (their session, the CSRF token in their forms): a CDN or a caching proxy in front of the app caches onlypublic/files (STATIC_CACHE_CONTROL), never pages.